home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Information / Digests / CSMP Digest / volume 3 / csmp-digest-v3-059 / doubleCR.1 < prev   
Encoding:
Text File  |  1995-12-31  |  84.1 KB  |  2,602 lines

  1. C.S.M.P. Digest             Mon, 19 Sep 94       Volume 3 : Issue 59
  2.  
  3. Today's Topics:
  4.  
  5.         AppleGuide script examples anyone?
  6.         Crazy error alert messages?
  7.         Goto Pro's and Con's
  8.         Need help with saving-writing structs to a file.
  9.         PBCatSearch-catChangedErr
  10.         PixToPic
  11.         Slashed Progress Bar
  12.  
  13.  
  14.  
  15. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  16. (pottier@clipper.ens.fr).
  17.  
  18. The digest is a collection of article threads from the internet newsgroup
  19. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  20. regularly and want an archive of the discussions.  If you don't know what a
  21. newsgroup is, you probably don't have access to it.  Ask your systems
  22. administrator(s) for details.  If you don't have access to news, you may
  23. still be able to post messages to the group by using a mail server like
  24. anon.penet.fi (mail help@anon.penet.fi for more information).
  25.  
  26. Each issue of the digest contains one or more sets of articles (called
  27. threads), with each set corresponding to a 'discussion' of a particular
  28. subject.  The articles are not edited; all articles included in this digest
  29. are in their original posted form (as received by our news server at
  30. nef.ens.fr).  Article threads are not added to the digest until the last
  31. article added to the thread is at least two weeks old (this is to ensure that
  32. the thread is dead before adding it to the digest).  Article threads that
  33. consist of only one message are generally not included in the digest.
  34.  
  35. The digest is officially distributed by two means, by email and ftp.
  36.  
  37. If you want to receive the digest by mail, send email to listserv@ens.fr
  38. with no subject and one of the following commands as body:
  39.     help                        Sends you a summary of commands
  40.     subscribe csmp-digest Your Name    Adds you to the mailing list
  41.     signoff csmp-digest            Removes you from the list
  42. Once you have subscribed, you will automatically receive each new
  43. issue as it is created.
  44.  
  45. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  46. Questions related to the ftp site should be directed to
  47. scott.silver@dartmouth.edu. Currently no previous volumes of the CSMP
  48. digest are available there.
  49.  
  50. Also, the digests are available to WAIS users.  To search back issues
  51. with WAIS, use comp.sys.mac.programmer.src. With Mosaic, use
  52. http://www.wais.com/wais-dbs/comp.sys.mac.programmer.html.
  53.  
  54.  
  55. -------------------------------------------------------
  56.  
  57. >From d.a.davies@bham.ac.uk (David Davies)
  58. Subject: AppleGuide script examples anyone?
  59. Date: Thu, 01 Sep 1994 14:27:20 +0000
  60. Organization: Birmingham University, UK.
  61.  
  62. Has anyone had a go at writing scripts for AppleGuide? Would anyone mind
  63. showing me just the simplest example if they have one. I've seen lots of
  64. compiled guides working but not seen the source for any as yet. I have a
  65. version of GuideMaker from one of the 7.5 beta CDs and I wanted to have a
  66. go at making a Guide myself...
  67.  
  68. Thanks,
  69.  
  70. -- 
  71. David Davies
  72.  
  73. Department of Physiology, University of Birmingham, UK.
  74.  
  75. Tel: 021 414 3255        Fax: 021 414 6924
  76.  
  77. http://medweb.bham.ac.uk/http/signatures/davies.html
  78.  
  79. +++++++++++++++++++++++++++
  80.  
  81. >From quinn@cs.uwa.edu.au (Quinn "The Eskimo!")
  82. Date: Fri, 02 Sep 1994 11:58:43 +0800
  83. Organization: Department of Computer Science, The University of Western Australia
  84.  
  85. In article <d.a.davies-0109941427200001@med262.bham.ac.uk>,
  86. d.a.davies@bham.ac.uk (David Davies) wrote:
  87.  
  88. >Has anyone had a go at writing scripts for AppleGuide?
  89.  
  90. Yes (:
  91.  
  92. >Would anyone mind showing me just the simplest example if they have one.
  93.  
  94. [Well it's not simple but it is comprehensive.]  I just posted the source
  95. code to the Anarchie Guide to MacGifts, so it should show up on UMich and
  96. Info-Mac mirrors soon.
  97.  
  98. Here are the blurb I attached to the MacGifts mailing...
  99.  
  100. >Attached is the Anarchie Guide source code distribution.  Anarchie Guide
  101. >is one of the first publically available guides and I decided to make its
  102. >source code available for two reasons.  Firstly itπs very hard to localise
  103. >a guide without source code. Secondly there is no publically available
  104. >guide source code and I thought it would be a good chance to rectify that.
  105. >
  106. >You need GuideMaker to be able to build this source however the source
  107. >code files are text files and you can browse them with any text editor.
  108.  
  109. For those of you too excited to wait, you can FTP it from...
  110.  
  111.   ftp://redback.cs.uwa.edu.au/Others/Quinn/
  112.  
  113. Share and Enjoy.
  114. -- 
  115. Quinn "The Eskimo!"        "Scout in a can. Simple, cheap, easy
  116.                             to use and it's expendable!"
  117.   Now if only Redback would stay up for more than 5 minutes, huh Pete?
  118.  
  119. ---------------------------
  120.  
  121. >From rtmd30@email.sps.mot.com (Greg Ferguson)
  122. Subject: Crazy error alert messages?
  123. Date: Tue, 23 Aug 1994 20:45:12 GMT
  124. Organization: Motorola, Inc.
  125.  
  126. Hi,
  127.  
  128. We're looking for some ideas for out-of-the-ordinary Alert messages.
  129.  
  130. My manager suggested the following one day:
  131.  
  132. I suggest that we use this as the standard unanticipated error message in
  133. all applications that we develop.  That is, after analyzing all know error
  134. conditions (which hopefully would present a relevant error message),
  135. display the following message as a last resort:
  136.  
  137. AN ERROR HAS JUST OCCURRED WHICH WAS PREVIOUSLY THOUGHT TO BE IMPOSSIBLE.
  138.  
  139. (taken from an old mainframe manual)
  140.  
  141. This is for those "we're going to crash if you do that again" type situations.
  142.  
  143. BTW, we can afford to be a bit frivolous as this is for in-house and test
  144. code. :-)
  145.  
  146. Thanks,
  147.  
  148. Greg
  149.  
  150. -- 
  151.  
  152. Greg Ferguson
  153. rtmd30@email.sps.mot.com
  154.  
  155. +++++++++++++++++++++++++++
  156.  
  157. >From Jeff Abrahamson <Jeff@purple.com>
  158. Date: Wed, 24 Aug 94 08:18:36 -0500
  159. Organization: Purple
  160.  
  161.  
  162. In article <rtmd30-2308941345120001@pangaea.sps.mot.com>, Greg Ferguson writes:
  163.  
  164. > We're looking for some ideas for out-of-the-ordinary Alert messages.
  165. > My manager suggested the following one day:
  166. > I suggest that we use this as the standard unanticipated error message in
  167. > all applications that we develop.  That is, after analyzing all know error
  168. > conditions (which hopefully would present a relevant error message),
  169. > display the following message as a last resort:
  170. > AN ERROR HAS JUST OCCURRED WHICH WAS PREVIOUSLY THOUGHT TO BE IMPOSSIBLE.
  171. > (taken from an old mainframe manual)
  172. > This is for those "we're going to crash if you do that again" type 
  173. situations.
  174. > BTW, we can afford to be a bit frivolous as this is for in-house and test
  175. > code. :-)
  176.  
  177. Well, then, how about:
  178.  
  179.     A subspace error (-129937) has occurred. Please check
  180.     this universe for consistency.
  181.  
  182. or
  183.  
  184.     An ATSM error has occurred. Please quit as soon as possible
  185.     to avoid previous crashes.
  186.  
  187. [ATSM is the Advanced Time Services Manager. It was discussed either here in a 
  188. previous thread or on the CW mailing list. Jens Alfke has most thoroughly 
  189. documented its use. :-) ]
  190.  
  191. -Jeff Abrahamson
  192.  clio!jeff@vu-vlsi.ee.vill.edu
  193.  
  194. +++++++++++++++++++++++++++
  195.  
  196. >From kenlong@netcom.com (Ken Long)
  197. Date: Wed, 24 Aug 1994 15:18:50 GMT
  198. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  199.  
  200. How about:
  201.  
  202. "Yours is the only Macintosh this error ever occurred on."
  203.    "Please report what you did to cause it to Apple."
  204.  
  205. or:
  206.  
  207. "It broke!"
  208.  
  209. or:
  210.  
  211. "Why should I tell YOU what there error number was?"
  212.       "You'll never be able to correct it!"
  213.  
  214. "Try that again and you'll be ordered to use IBM's
  215.                  for 6 months"
  216.  
  217. All seriousness aside...
  218.  
  219. -Ken-
  220.  
  221. +++++++++++++++++++++++++++
  222.  
  223. >From ogawa@teleport.com (Arthur Ogawa)
  224. Date: Wed, 24 Aug 94 21:25:02 GMT
  225. Organization: TeX Consultants
  226.  
  227. In Article <94082408183600240@purple.com>, Jeff Abrahamson <Jeff@purple.com>
  228. wrote:
  229. >
  230. >In article <rtmd30-2308941345120001@pangaea.sps.mot.com>, Greg Ferguson writes:
  231. >
  232. >> We're looking for some ideas for out-of-the-ordinary Alert messages.
  233. [deleted]
  234. Here's one from TeX, by Donald Knuth:
  235.  
  236. "This can't happen"
  237. Arthur Ogawa, TeX Consultants, Kaweah CA 93237-0051
  238. Ph: 209/561-4585, FAX: -4584
  239. PGP Key: finger -l ogawa@teleport.com
  240.  
  241. +++++++++++++++++++++++++++
  242.  
  243. >From spencerl@crl.com (Spencer Low)
  244. Date: Wed, 24 Aug 1994 16:45:44 -0800
  245. Organization: LowTek Creations
  246.  
  247. In article <94082408183600240@purple.com>, clio!jeff@vu-vlsi.ee.vill.edu wrote:
  248. >     A subspace error (-129937) has occurred. Please check
  249. >     this universe for consistency.
  250.  
  251. Of course, you could also include the following one (for you develop readers):
  252.  
  253.       A subspace error (-16.7 * 10^6) has occured. pi does *not*
  254.       equal 3.141592654. Please make sure your universe is in
  255.       existance.
  256.  
  257. Spencer
  258. ________________________________________________________________________
  259.   Spencer "MaxRAM" Low ------ LowTek Creations ----- spencerl@crl.com
  260.  
  261. +++++++++++++++++++++++++++
  262.  
  263. >From Manuel Veloso <veloso@netcom.com>
  264. Date: Fri, 26 Aug 1994 06:11:38 GMT
  265. Organization: Ibex Productions
  266.  
  267. In article <rtmd30-2308941345120001@pangaea.sps.mot.com> Greg Ferguson,
  268. rtmd30@email.sps.mot.com writes:
  269. >We're looking for some ideas for out-of-the-ordinary Alert messages.
  270.  
  271. Why not just use the simple, yet poignant,
  272.  
  273. "Whoops!"
  274.  
  275. or the more minimal message from mpw gcc
  276.  
  277. "Ack!"
  278.  
  279. or the ultimate testing message from Radiation,
  280.  
  281. "Warning! The radiation shield on your Macintosh has failed.
  282. Please step back 5 feet."
  283.  
  284. +++++++++++++++++++++++++++
  285.  
  286. >From goo@cwis.unomaha.edu (Kent Radek)
  287. Date: 27 Aug 94 03:19:27 GMT
  288. Organization: University of Nebraska Omaha
  289.  
  290. I once got a message like this in the CodeWarrior debugger:
  291.  
  292. "An error #-930 has occurred, because an error occurred."
  293.  
  294. goo
  295.  
  296. +++++++++++++++++++++++++++
  297.  
  298. >From reinder@neuretp.biol.ruu.nl (Reinder Verlinde)
  299. Date: Wed, 31 Aug 1994 14:41:13 GMT
  300. Organization: Rijksuniversiteit Utrecht
  301.  
  302. How about:
  303.  
  304.   "The item <name> could not be deleted because it doesn't exist"
  305.  
  306. (Macintosh Finder)
  307.  
  308. or:
  309.  
  310.   "numeric constant too long (> 255 characters)"
  311.  
  312. (MPW C++)
  313.  
  314.   "too many errors on one line. Use fewer"
  315.   "This union already has a perfectly good definition"
  316.   "This struct already has a perfectly good definition"
  317.   "This array has no size, and that's bad"
  318.   "Only one parameter per register please"
  319.   "a typedef name was a complete surprise to me at this point in your
  320. program"
  321.   "type in (cast) must be scalar; ANSI 3.3.4; page 39, lines 10-11 (I
  322. know
  323.    you don't care, I'm just trying to annoy you)"
  324.   "Call me paranoid but finding '/*' inside this comment makes me
  325. suspicious"
  326.   "Trailing comma not permitted in enum definition.  (This time I'm
  327. letting
  328.    you off with a warning)"
  329.   "This function has an explicit return type and deserves a return
  330. value"
  331.   "...And the lord said, 'lo, there shall only be case or default
  332. labels
  333.    inside a switch statement'"
  334.   "Symbol table full - fatal heap error; please go buy a RAM upgrade
  335. from
  336.    your local Apple dealer"
  337.   "String literal too long (I let you have 512 characters, that's 3
  338. more than
  339.    ANSI said I should)"
  340.   "This label is the target of a goto from outside of the block
  341. containing
  342.    this label AND this block has an automatic variable with an
  343. initializer
  344.    AND your window wasn't wide enough to read this whole error message"
  345.  
  346. (all from MPW C)
  347.  
  348. reinder@neuretp.biol.ruu.nl (Reinder Verlinde)
  349.  
  350. +++++++++++++++++++++++++++
  351.  
  352. >From deanp@zikzak.apana.org.au (Dean Perry)
  353. Date: 4 Sep 1994 04:29:15 GMT
  354. Organization: Zikzak public access UNIX, Melbourne Australia
  355.  
  356. Greg Ferguson (rtmd30@email.sps.mot.com) wrote:
  357.  
  358. : We're looking for some ideas for out-of-the-ordinary Alert messages.
  359.  
  360. This one, hijacked from an old (85?) BMUG newsletter (ish)
  361.  
  362. "Really spin the hard disk at 90000 rpm?"
  363.  
  364. <YES>   <MAYBE>
  365.  
  366.  
  367. dean
  368. --
  369.         Zikzak public access UNIX, Melbourne, Australia.
  370.  
  371. +++++++++++++++++++++++++++
  372.  
  373. >From deanp@zikzak.apana.org.au (Dean Perry)
  374. Date: 5 Sep 1994 14:22:48 GMT
  375. Organization: Zikzak public access UNIX, Melbourne Australia
  376.  
  377. Or this cutie, from MacApp this evening:
  378.  
  379. Could not complete the command "x" because "class", an internal component 
  380. is missing.  Call Apple for a secret decoder ring.
  381.  
  382. dean (again)
  383. --
  384.         Zikzak public access UNIX, Melbourne, Australia.
  385.  
  386. ---------------------------
  387.  
  388. >From steven.webber@digitec.co.za (Steven Webber) 
  389. Subject: Goto Pro's and Con's
  390. Date: 23 Aug 94 23:21:00 GMT
  391. Organization: Digitec Online
  392.  
  393. Hi there.
  394.  
  395. I've got a question for all you programmers out there. 
  396.  
  397. Do you use goto's in your code?  
  398.  
  399. Do you think using Goto's is a bad or good idea?
  400.  
  401. Why do you like/dislike using them?
  402.  
  403. Everybodies ideas would be most welcome.
  404.  
  405. Thanks 
  406. Steven.
  407.  
  408. Steven.Webber@Digitec.co.za
  409. ___ Blue Wave/QWK v2.12 OS/2
  410.  
  411. - --
  412. - - Digitec Online --- Johannesburg, South Africa --- tel +27 11 476-2008 ---
  413. - - You can TELNET Africa's biggest and most popular BBS on 196.11.62.106 ---
  414.  
  415. +++++++++++++++++++++++++++
  416.  
  417. >From s3026557@titanic.mpce.mq.edu.au (Duncan Anker)
  418. Date: 24 Aug 1994 10:04:44 GMT
  419. Organization: Macquarie University, School of Mathematics, Physics, Computing and Electronics
  420.  
  421. Steven Webber (steven.webber@digitec.co.za) wrote:
  422. : Hi there.
  423.  
  424. : I've got a question for all you programmers out there. 
  425.  
  426. : Do you use goto's in your code?  
  427.  
  428. : Do you think using Goto's is a bad or good idea?
  429.  
  430. : Why do you like/dislike using them?
  431.  
  432. : Everybodies ideas would be most welcome.
  433.  
  434. Thou shalt not use gotos. Neither shalt thou abolish them entirely.
  435.  
  436. Personally, I don't use them, although they can be useful when escaping
  437. from error situations in deeply nested code (or so I've heard).
  438.  
  439. If you find yourself using gotos, consider rewriting your functions. :-)
  440.  
  441. cheers.
  442.  
  443. --
  444. s3026557@titanic.mpce.mq.edu.au * Duncan Anker * e3026557@hardy.ocs.mq.edu.au
  445.  
  446. If you're a horse, and someone gets on you, and falls off, and then gets right
  447. back on you, I think you should buck him off right away.
  448.  
  449. +++++++++++++++++++++++++++
  450.  
  451. >From eascharf@u.washington.edu (Elizabeth Scharf)
  452. Date: 24 Aug 1994 13:59:22 GMT
  453. Organization: University of Washington, Seattle
  454.  
  455. I am fairly partial to break/continue statements for making loop 
  456. execution easier to read.  I also use goto for error handling in some 
  457. routines, but with several restrictions, like only one label per routine 
  458. called "CleanUp:" and only one return point which is after CleanUp.  I 
  459. try to write code that can determine its error state and what needs 
  460. cleaning up at the end so as to make the goto basically like the end of a 
  461. bunch of if statements, but without the code waterfall.  Other than that, 
  462. I try to avoid them because they make things harder to read and maintain.
  463.  
  464. Donald Knuth presents several examples where using gotos are beneficial, 
  465. usually for algorithm optomization (see Knuth, "Literate Programming")  A 
  466. good read in any case.
  467.  
  468. rmgw
  469.  
  470. This is not my account:  Please address replies to hawkfish@aol.com
  471.  
  472. Disclaimer:  All views expressed are entirely my own and do not reflect 
  473. the opinions of Elizabeth Scharf or the University of Washington.
  474.  
  475. - ---------------------------------------------------------------------------
  476. Richard Wesley             | "No, No No, 'Eureka' is Greek; it means 'This
  477. hawkfish@aol.com           |  bath is too hot'"
  478. 71062.1711@compuserve.com  |                      - Dr. Who
  479. - ---------------------------------------------------------------------------
  480.  
  481.  
  482. +++++++++++++++++++++++++++
  483.  
  484. >From dennis@mr2.ece.cmu.edu (Dennis J. Ciplickas)
  485. Date: 24 Aug 1994 14:25:39 GMT
  486. Organization: Electrical and Computer Engineering, Carnegie Mellon
  487.  
  488.  
  489. In article <300.310.uupcb@digitec.co.za> steven.webber@digitec.co.za (Steven Webber)  writes:
  490. >Hi there.
  491. >I've got a question for all you programmers out there. 
  492. >Do you use goto's in your code?  
  493. >Do you think using Goto's is a bad or good idea?
  494. >Why do you like/dislike using them?
  495.  
  496. (You didn't specify which language you were thinking about, but I'll
  497. assume C.)  I regularly use an "error exit" goto construct in my C
  498. code because it's just too damn difficult to unravel yourself at each
  499. point where you might need to exit.  A common example is in a routine
  500. that must allocate a few different items, and if any one of them fails
  501. you complain to the user and quit.  For example:
  502.  
  503. OSErr Allocater(void)
  504. {
  505.   OSErr err;
  506.   Handle h1,h2;
  507.   Ptr p1,p2;
  508.  
  509.   // null out our block pointers so that if we have to leave
  510.   // prematurely, only those that actually got allocated get
  511.   // deallocated.
  512.   h1 = h2 = NULL;
  513.   p1 = p2 = NULL;
  514.  
  515.   // now allocate all the blocks
  516.   if (!(h1 = NewHandle(10))) {
  517.     err = MemError();
  518.     showerror(1,"Memory Error %d allocating h1.");
  519.     goto errexit;
  520.     }
  521.  
  522.   if (!(h2 = NewHandle(20))) {
  523.     err = MemError();
  524.     showerror(1,"Memory Error %d allocating h2.");
  525.     goto errexit;
  526.     }
  527.  
  528.   if (!(p1 = NewPtr(10))) {
  529.     err = MemError();
  530.     showerror(1,"Memory Error %d allocating p1.");
  531.     goto errexit;
  532.     }
  533.  
  534.   if (!(p2 = NewPtr(10))) {
  535.     err = MemError();
  536.     showerror(1,"Memory Error %d allocating p2.");
  537.     goto errexit;
  538.     }
  539.  
  540.   // then do some work.
  541.   ...
  542.   if (err = DoSomethingElse(h1,h2)) goto errexit;
  543.   ...
  544.   err = noErr;
  545.  
  546.   // deallocate and leave
  547.  
  548. errexit:
  549.   if (h1) DisposHandle(h1);
  550.   if (h2) DisposHandle(h2);
  551.   if (p1) DisposPtr(p1);
  552.   if (p2) DisposPtr(p2);
  553.  
  554.   return err;
  555. }
  556.  
  557. -Dennis
  558.  
  559. +++++++++++++++++++++++++++
  560.  
  561. >From pcastine@prz.tu-berlin.de (Peter Castine)
  562. Date: Wed, 24 Aug 1994 15:24:35 GMT
  563. Organization: Process Control Center
  564.  
  565. In article <300.310.uupcb@digitec.co.za>, steven.webber@digitec.co.za
  566. (Steven Webber) wrote:
  567.  
  568. > Hi there.
  569. > I've got a question for all you programmers out there. 
  570. > Do you use goto's in your code?  
  571. > Do you think using Goto's is a bad or good idea?
  572. > Why do you like/dislike using them?
  573. > Everybodies ideas would be most welcome.
  574.  
  575. Haven't used a goto since I stopped programming in BASIC (which was when I
  576. bought my own Mac in '86). Actually, the last BASIC I used (BBC BASIC on
  577. an Acorn Beeb) let me avoid GOTOs _almost_ entirely, so add a few years.
  578.  
  579. The problems with GOTO are discussed thoroughly in Anthony Hoare's seminal
  580. paper ``GOTO cosidered dangerous'' (Sorry, I don't have the complete
  581. reference) and in every book on structured programming techniques written
  582. since.
  583.  
  584. Essentially, there is nothing you can do with GOTO you can't do with
  585. procedure calls, stuctured loops, and if-then-else constructs. Structured
  586. code is generally easier to read and understand (and, hence, easier to
  587. modify without causing it to stop working). There are some exceptional
  588. situations where GOTOs may make sense (C's break, continue, and exit
  589. statements are semi-structured GOTOs in disguise; in other languages you
  590. might use a GOTO where you'd see a break in C).
  591.  
  592. -- 
  593. Peter Castine               | C (n.): A programming language that is sort of
  594. pcastine@prz.tu-berlin.de   | like Pascal except more like assembly except
  595. Process Control Center      | that it isn't very much like either one, or
  596. Technical University Berlin | anything else.                  -- Ray Simard
  597.  
  598. +++++++++++++++++++++++++++
  599.  
  600. >From Darrin Cardani <Darrin.Cardani@AtlantaGA.NCR.COM>
  601. Date: Wed, 24 Aug 1994 13:31:38 GMT
  602. Organization: AT&T Global Information Solutions, Atlanta
  603.  
  604. >In article <300.310.uupcb@digitec.co.za> Steven Webber writes: 
  605. >Hi there.
  606. >
  607. >I've got a question for all you programmers out there. 
  608. >
  609. >Do you use goto's in your code?  
  610.  
  611. Occasionally. The only time I really use them (well, in non-BASIC programming ;)
  612. is for error handling. I often have a set of Sound Manager
  613. calls that look something like this:
  614.  
  615. {
  616.    SndError = SndManagerCall1 (blah);
  617.    if (SndError != noError)
  618.      goto Cleanup;
  619.  
  620.    SndError = SndManagerCall2 (blah);
  621.    if (SndError != noError)
  622.       goto Cleanup;
  623.  
  624. ..etc...
  625.  
  626.    return (noError);
  627.  
  628.    Cleanup:
  629.       <Several lines of cleanup code, and return an error>
  630. }
  631.  
  632. >Do you think using Goto's is a bad or good idea?
  633.  
  634. In general I use the control structures provided by the
  635. language since that's what they were made for. They're
  636. a bad idea if they obscure your code and don't add anything
  637. to it. I think in the above, it saves space and is pretty clear.
  638.  
  639. Darrin
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647. +++++++++++++++++++++++++++
  648.  
  649. >From jwbaxter@olympus.net (John W. Baxter)
  650. Date: Wed, 24 Aug 1994 08:17:32 -0700
  651. Organization: Internet for the Olympic Peninsula
  652.  
  653. In article <300.310.uupcb@digitec.co.za>, steven.webber@digitec.co.za
  654. (Steven Webber) wrote:
  655.  
  656. > Hi there.
  657. > I've got a question for all you programmers out there. 
  658. > Do you use goto's in your code?  
  659.  
  660. I use them when I feel they are the cleanest solution to a dirty problem. 
  661. As Sean mentioned, error handling can be one such, in a language such as
  662. see which doesn't provide something better.  C++ with exceptions offers
  663. something better...too bad it doesn't exist yet in many compilers.
  664.  
  665. > Do you think using Goto's is a bad or good idea?
  666. > Why do you like/dislike using them?
  667.  
  668. The cost of software is more in the maintenance than in the original
  669. coding.  Uncontrolled use of gotos usually makes the maintenance more
  670. expensive (and sometimes essentially impossible:  it's cheaper to start
  671. fresh), because it tends to make the code hard to read (for a human...the
  672. compiler does fine).  On the other hand, dirty tricks to avoid gotos has a
  673. similar effect...the code is hard to maintain.
  674.  
  675. But what do I know???...I've only been doing this since the late 1950s
  676. (and not continuously during that time).
  677.    --John
  678.  
  679. -- 
  680. John Baxter    Port Ludlow, WA, USA  [West shore, Puget Sound]
  681.    "Occasionally...astronomers add a second to either June 31 or
  682.     December 31..."   IM: OS Utilities, p 4-12
  683.    jwbaxter@pt.olympus.net
  684.  
  685. +++++++++++++++++++++++++++
  686.  
  687. >From h+@nada.kth.se (Jon W{tte)
  688. Date: Wed, 24 Aug 1994 23:10:27 +0200
  689. Organization: Royal Institute of Something or other
  690.  
  691. In article <300.310.uupcb@digitec.co.za>,
  692. steven.webber@digitec.co.za (Steven Webber)  wrote:
  693.  
  694. >Do you use goto's in your code?  
  695.  
  696. Yes.
  697.  
  698. >Do you think using Goto's is a bad or good idea?
  699. >Why do you like/dislike using them?
  700.  
  701. Sometimes they help structure code immensely, like when you 
  702. test for pre-conditions and want to take an early exit, but 
  703. still clean up stuff. Also for "retry" kinds of things it's 
  704. much simpler and easier on the eyes with a strategically-placed 
  705. goto.
  706.  
  707. C++ stack-based objects help reduce gotos, but not eliminate 
  708. them totally.
  709.  
  710. The controversy these days is on non-local gotos, like 
  711. longjmp() and C++ try/catch exceptions. I tend to like these as 
  712. well, but they _do_ add a need for careful structuring in order 
  713. to be used cleanly and effectively.
  714.  
  715.  
  716.  
  717.  
  718. --
  719.   Jon W‰tte (h+@nada.kth.se), Hagagatan 1, 113 48 Stockholm, Sweden
  720.  "Don't use the Layer Manager"
  721.  
  722.  
  723. +++++++++++++++++++++++++++
  724.  
  725. >From bootstrap1@aol.com (Bootstrap1)
  726. Date: 24 Aug 1994 17:40:16 -0400
  727. Organization: America Online, Inc. (1-800-827-6364)
  728.  
  729. In article <DENNIS.94Aug24102539@mr2.ece.cmu.edu>, dennis@mr2.ece.cmu.edu
  730. (Dennis J. Ciplickas) writes:
  731.  
  732. > I regularly use an "error exit" goto construct in my C
  733. > code because it's just too damn difficult to unravel yourself at each
  734. > point where you might need to exit.  A common example is in a routine
  735. > that must allocate a few different items, and if any one of them fails
  736. > you complain to the user and quit.  For example:
  737.  
  738. While I think it is fine to use a goto construct in a well structured way
  739. such as you illustrate in your example, I still never use them myself.  As
  740. with using continue and break in loops and return in the middle of
  741. functions, I find it makes the flow of a function more difficult to
  742. follow.  Knowing that a function starts executing at the top and falls
  743. straight through all the way to the bottom makes debugging and reading
  744. code much easier, at least for me.  And you can still avoid having to
  745. unravel on reaching an error conditions, as well as the dreaded "code
  746. waterfall" someone else mentioned, without using gotos, as the following
  747. edit of your sample shows
  748.  
  749. OSErr Allocater(void) {
  750.   OSErr err;
  751.   Handle h1,h2;
  752.   Ptr p1,p2;
  753.  
  754.   // null out our block pointers so that if we have to leave
  755.   // prematurely, only those that actually got allocated get
  756.   // deallocated.
  757.   h1 = h2 = NULL;
  758.   p1 = p2 = NULL;
  759.  
  760.   h1 = NewHandle(10);
  761.   if ((err = MemError()) != noErr)
  762.     showerror(1,"Memory Error %d allocating h1.");
  763.  
  764.   if (err == noErr) {
  765.     h2 = NewHandle(20);
  766.     if ((err = MemError()) != noErr)
  767.       showerror(1,"Memory Error %d allocating h2.");
  768.   }
  769.  
  770.   if (err == noErr) {
  771.     p1 = NewPtr(10);
  772.     if ((err = MemError()) != noErr)
  773.       showerror(1,"Memory Error %d allocating p1.");
  774.   }
  775.  
  776.   if (err == noErr) {
  777.     p2 = NewPtr(10);
  778.     if ((err = MemError()) != noErr)
  779.       showerror(1,"Memory Error %d allocating p2.");
  780.   }
  781.  
  782.   // then do some work.
  783.   ...
  784.   if (err == noErr)
  785.     err = DoSomethingElse(h1,h2);
  786.  
  787.   if (err != noErr) {
  788.     // deallocate
  789.  
  790.     if (h1) DisposHandle(h1);
  791.     if (h2) DisposHandle(h2);
  792.     if (p1) DisposPtr(p1);
  793.     if (p2) DisposPtr(p2);
  794.   }
  795.  
  796.   return err;
  797. }
  798.  
  799.  
  800. +++++++++++++++++++++++++++
  801.  
  802. >From howard@netcom.com (Howard Berkey)
  803. Date: Wed, 24 Aug 1994 22:42:04 GMT
  804. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  805.  
  806. In article <300.310.uupcb@digitec.co.za>,
  807. Steven Webber <steven.webber@digitec.co.za> wrote:
  808. >Hi there.
  809. >
  810. >I've got a question for all you programmers out there. 
  811. >
  812. >Do you use goto's in your code?  
  813. >
  814.  
  815. Oh, about as often as longjmp()  :-)
  816.  
  817.  
  818. >Do you think using Goto's is a bad or good idea?
  819. >
  820.  
  821. I can think of very few situations that require them, if any.  One
  822. might be removal of recursion in a routine that would be uglier to do
  823. in any other way.  *might* be.  99% of the time continue or break
  824. work as well or better in the remaining situations.
  825.  
  826. >Why do you like/dislike using them?
  827. >
  828.  
  829. It decreases readability of your code, complicates flow, is ugly, and
  830. makes your co-workers laugh at you.  It makes bugs potentially harder
  831. to find.  It is usually done as a quick hack or kludge (IOW it
  832. probably introduces a new bug).  
  833.  
  834.  
  835. -H-
  836.  
  837.  
  838.  
  839. -- 
  840. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  841. Howard Berkey                                             howard@netcom.com   
  842. Segmentation Fault (core dumped)
  843.  
  844. +++++++++++++++++++++++++++
  845.  
  846. >From hulburt@leland.stanford.edu (Greg Payne)
  847. Date: 25 Aug 1994 02:29:26 GMT
  848. Organization: Stanford University
  849.  
  850. In article <300.310.uupcb@digitec.co.za>
  851. steven.webber@digitec.co.za (Steven Webber)  writes:
  852.  
  853. > Hi there.
  854. > I've got a question for all you programmers out there. 
  855. > Do you use goto's in your code?  
  856. > Do you think using Goto's is a bad or good idea?
  857. > Why do you like/dislike using them?
  858. > Everybodies ideas would be most welcome.
  859. > Thanks 
  860. > Steven.
  861.  
  862. Well, here is my 2 cents:
  863.  
  864. I personally dont use gotos (too many people said they
  865. were bad in all my cs classes).  I supposed they have 
  866. their place, but they can really make code hard to 
  867. understand.  I translated an airfoil code from fortran
  868. to c, and it really wasn't documented too well.  I did
  869. know most of the general method, through, but it was
  870. a real pain going through goto-loops that wandered all over
  871. the place to do the same thing a switch or if then else
  872. in c.  Unless it is to get out of a deeply nest loop
  873. or for error-handling, I'd say they are probably bad 
  874. programming.
  875.  
  876. Greg Payne
  877. greg@aerometrics.com
  878.  
  879. +++++++++++++++++++++++++++
  880.  
  881. >From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
  882. Date: Thu, 25 Aug 1994 19:18:17 +1200 (NZST)
  883. Organization: (none)
  884.  
  885. steven.webber@digitec.co.za (Steven Webber)  writes:
  886. > I've got a question for all you programmers out there. 
  887. > Do you use goto's in your code?  
  888.  
  889. In assembler: all the time.
  890. In C or Pascal:  I don't remember the last time.  10 years ago?  You
  891. don't need them.
  892.  
  893. -- Bruce
  894.  
  895. +++++++++++++++++++++++++++
  896.  
  897. >From radixinc@aol.com (RadixInc)
  898. Date: 25 Aug 1994 15:53:01 -0400
  899. Organization: America Online, Inc. (1-800-827-6364)
  900.  
  901. In article <2860687096@hoult.actrix.gen.nz>, Bruce@hoult.actrix.gen.nz
  902. (Bruce Hoult) writes:
  903.  
  904. <<I've got a question for all you programmers out there. 
  905.  
  906. Do you use goto's in your code? >>
  907.  
  908. In C, I use goto once in a while for one purpose only: to get out of a
  909. loop or deep if... structure when something awful happens. I used to write
  910. the gotos myself, but I've been using the exception-handling macros that
  911. were in a "d e v e l o p" article a few issues back, and they look like
  912. function calls, even though they turn into gotos. If I had real exception
  913. handling I wouldn't need to use goto at all, though there is something
  914. nice about having the error handling and recovery/cleanup code in the same
  915. function that generates the error.
  916.  
  917. I used gotos once before to write a state-machine parser, but again I had
  918. macros to hide the goto/label stuff. This technique was discussed in
  919. "Computer Language" magazine, May 1991, and it worked out very well.
  920.  
  921. There are times when goto is the best and cleanest way to do something,
  922. but you have to discipline yourself to use goto only when you are
  923. convinced that there is no cleaner way to go. I've yet to see a decent C
  924. programmer use goto in the offhand way a lot of BASIC programmers use it.
  925.  
  926. A lot of the anti-goto sentiment comes out of Wirth's article "GOTO
  927. considered harmful," and he was referring to languages current at the
  928. time: PL/I, Fortran, and most of all BASIC. The typical Pascal book
  929. (including Wirth's) rail against goto, but he also acknowledges the (rare)
  930. necessity of it, because Pascal does after all implement goto. For
  931. example, removing tail recursion from algorithms like Quicksort is
  932. arguably best done with a goto, even in Pascal. (Of course there are other
  933. ways to do this; please don't assail me with goto-less Quicksorts). Wirth
  934. is right about the careless and unnecessary use of goto common in Fortran,
  935. BASIC, and PL/I, but those languages don't (or didn't at the time) have
  936. the control structures needed to obviate the use of goto. In modern
  937. languages, and modern implementations of Fortran and BASIC, the goto is
  938. mostly unnecessary, as it is in C and Pascal.
  939.  
  940. Gregory Jorgensen
  941. Radix Consulting Inc.
  942.  
  943.  
  944. +++++++++++++++++++++++++++
  945.  
  946. >From alexr@apple.com (Alexander M. Rosenberg)
  947. Date: Thu, 25 Aug 1994 21:26:02 GMT
  948. Organization: Hackers Anonymous
  949.  
  950. In article <300.310.uupcb@digitec.co.za>, steven.webber@digitec.co.za
  951. (Steven Webber) wrote:
  952.  
  953. > I've got a question for all you programmers out there. 
  954. > Do you use goto's in your code?  
  955. > Do you think using Goto's is a bad or good idea?
  956. > Why do you like/dislike using them?
  957.  
  958. Read Literate Programming by Donald Knuth. It includes an updated version
  959. of an old paper of his on this topic. I think that it should answer your
  960. questions quite nicely. (And it explained all those stupid looping
  961. constructs that Pascal has.)
  962.  
  963. - -------------------------------------------------------------------------
  964. -  Alexander M. Rosenberg  - INTERNET: alexr@apple.com      - Yoyodyne    -
  965. -  330 Waverley St., Apt B - UUCP:ucbvax!apple!alexr        - Propulsion  -
  966. -  Palo Alto, CA 94301     -                                - Systems     -
  967. -  (415) 329-8463          - Nobody is my employer so       - :-)         -
  968. -  (408) 974-3110          - nobody cares what I say.       -             -
  969.  
  970. +++++++++++++++++++++++++++
  971.  
  972. >From Bruce@hoult.actrix.gen.nz (Bruce Hoult)
  973. Date: Fri, 26 Aug 1994 11:25:15 +1200 (NZST)
  974. Organization: (none)
  975.  
  976. bootstrap1@aol.com (Bootstrap1) writes:
  977. > While I think it is fine to use a goto construct in a well structured way
  978. > such as you illustrate in your example, I still never use them myself.  As
  979. > with using continue and break in loops and return in the middle of
  980. > functions, I find it makes the flow of a function more difficult to
  981. > follow.  Knowing that a function starts executing at the top and falls
  982. > straight through all the way to the bottom makes debugging and reading
  983. > code much easier, at least for me.  And you can still avoid having to
  984. > unravel on reaching an error conditions, as well as the dreaded "code
  985. > waterfall" someone else mentioned, without using gotos, as the following
  986. > edit of your sample shows
  987.  
  988. A agree with your points, but dislike all the extra testing of err (both in
  989. error and normal situations) in your solution, and you're *still* obscuring
  990. the main flow of control in the normal situation.
  991.  
  992. I much prefer a "block" that uses break to exit when there is an error.
  993. Yes, I read your comment about break, and disagree.
  994.  
  995. Unfortunately, C and Pascal don't have a construct with this purpose, but
  996. one can easily be faked using "repeat until true" or "do { } while (0)"...
  997.  
  998. To further mangle this eample code:
  999.  
  1000. OSErr Allocater(void) {
  1001.   OSErr err;
  1002.   Handle h1,h2;
  1003.   Ptr p1,p2;
  1004.  
  1005.   // null out our block pointers so that if we have to leave
  1006.   // prematurely, only those that actually got allocated get
  1007.   // deallocated.
  1008.   h1 = h2 = NULL;
  1009.   p1 = p2 = NULL;
  1010.   
  1011.   do { // once only for error checking
  1012.  
  1013.     h1 = NewHandle(10);
  1014.     if ((err = MemError()) != noErr){
  1015.      showerror(1,"Memory Error %d allocating h1."); break;
  1016.     }
  1017.   
  1018.     h2 = NewHandle(20);
  1019.     if ((err = MemError()) != noErr){
  1020.       showerror(1,"Memory Error %d allocating h2."); break;
  1021.     }
  1022.   
  1023.     p1 = NewPtr(10);
  1024.     if ((err = MemError()) != noErr){
  1025.       showerror(1,"Memory Error %d allocating p1."); break;
  1026.     }
  1027.   
  1028.     p2 = NewPtr(10);
  1029.     if ((err = MemError()) != noErr){
  1030.       showerror(1,"Memory Error %d allocating p2."); break;
  1031.     }
  1032.   
  1033.     // then do some work.
  1034.     ...
  1035.     err = DoSomethingElse(h1,h2);
  1036.      
  1037.   } while (0);
  1038.  
  1039.   if (err != noErr) {
  1040.     // deallocate
  1041.  
  1042.     if (h1) DisposHandle(h1);
  1043.     if (h2) DisposHandle(h2);
  1044.     if (p1) DisposPtr(p1);
  1045.     if (p2) DisposPtr(p2);
  1046.   }
  1047.  
  1048.   return err;
  1049. }
  1050.  
  1051. +++++++++++++++++++++++++++
  1052.  
  1053. >From Jaeger@fquest.com (Brian Stern)
  1054. Date: 26 Aug 1994 03:40:36 GMT
  1055. Organization: The University of Texas at Austin, Austin, Texas
  1056.  
  1057. In article <DENNIS.94Aug24102539@mr2.ece.cmu.edu>, dennis@mr2.ece.cmu.edu
  1058. (Dennis J. Ciplickas) wrote:
  1059.  
  1060. > In article <300.310.uupcb@digitec.co.za> steven.webber@digitec.co.za
  1061. (Steven Webber)  writes:
  1062. > >Hi there.
  1063. > >I've got a question for all you programmers out there. 
  1064. > >Do you use goto's in your code?  
  1065. > >Do you think using Goto's is a bad or good idea?
  1066. > >Why do you like/dislike using them?
  1067. > (You didn't specify which language you were thinking about, but I'll
  1068. > assume C.)  I regularly use an "error exit" goto construct in my C
  1069. > code because it's just too damn difficult to unravel yourself at each
  1070. > point where you might need to exit.  A common example is in a routine
  1071. > that must allocate a few different items, and if any one of them fails
  1072. > you complain to the user and quit.  For example:
  1073. [code chopped]
  1074. > -Dennis
  1075.  
  1076. The fact is that memerrors aren't fatal.  there's nothing wrong with
  1077. something like the following:
  1078.  
  1079. OSErr Allocater(void)
  1080. {
  1081.   OSErr err;
  1082.   Handle h1,h2;
  1083.   Ptr p1,p2;
  1084.  
  1085.    h1 = NewHandle( 10 );
  1086.    h2 = NewHandle( 20 );
  1087.    p1 = NewPtr( 10 );
  1088.    p2 = NewPtr( 10 );
  1089.  
  1090.    if ( noErr != ( err = MemError() ) )
  1091.      {
  1092.          // then do some work.
  1093.      }
  1094.    else
  1095.    {
  1096.       //report your errors
  1097.    }
  1098.  
  1099.   if ( h1 ) DisposHandle( h1 );
  1100.   if ( h2 ) DisposHandle( h2 );
  1101.   if ( p1 ) DisposPtr( p1 );
  1102.   if ( p2 ) DisposPtr( p2 );
  1103.  
  1104.   return err;
  1105. }
  1106.  
  1107. While I won't categorically say that gotos are evil, I haven't used one
  1108. since I gave up Fortran.
  1109.  
  1110. -- 
  1111. Brian  Stern  :-{)}
  1112. Jaeger@fquest.com
  1113.  
  1114. +++++++++++++++++++++++++++
  1115.  
  1116. >From radixinc@aol.com (RadixInc)
  1117. Date: 26 Aug 1994 00:35:04 -0400
  1118. Organization: America Online, Inc. (1-800-827-6364)
  1119.  
  1120. In article <33isqt$sie@search01.news.aol.com>, radixinc@aol.com (RadixInc)
  1121. writes:
  1122.  
  1123. <<A lot of the anti-goto sentiment comes out of Wirth's article "GOTO
  1124. considered harmful,...>>
  1125.  
  1126. As one polite person pointed out to me by email, the paper "GOTO
  1127. Considered Harmful" was written be Edsger Dijkstra, not Niklaus Wirth. I
  1128. always get them confused--they both have unpronouncable last names. I
  1129. believe Dijkstra's paper appeared in the CACM, but I don't have it. My
  1130. point remains the same, only that perhaps Dijkstra is a bit more adamant
  1131. about not using GOTO than Wirth.
  1132.  
  1133. Gregory Jorgensen
  1134. Radix Consulting Inc.
  1135.  
  1136. +++++++++++++++++++++++++++
  1137.  
  1138. >From radixinc@aol.com (RadixInc)
  1139. Date: 26 Aug 1994 02:59:05 -0400
  1140. Organization: America Online, Inc. (1-800-827-6364)
  1141.  
  1142. In article <DENNIS.94Aug24102539@mr2.ece.cmu.edu>, dennis@mr2.ece.cmu.edu
  1143. (Dennis J. Ciplickas) wrote:
  1144.  
  1145. << I regularly use an "error exit" goto construct in my C code because
  1146. it's just too damn difficult to unravel yourself at each point where you
  1147. might need to exit.>>
  1148.  
  1149. There's a good article in "d e v e l o p," August 1992, called "Living In
  1150. An Exceptional World" by Sean Parent. He proposes an elegant mechanism for
  1151. handling exceptions with macros, including clean-up and recovery. His
  1152. technique uses macros that resolve to gotos, but it keeps the source code
  1153. clean. I've been using these macros for a year or so, and I haven't had to
  1154. use an actual goto since. Check it out.
  1155.  
  1156. Gregory Jorgensen
  1157. Radix Consulting Inc.
  1158.  
  1159. +++++++++++++++++++++++++++
  1160.  
  1161. >From dennis@mr2.ece.cmu.edu (Dennis J. Ciplickas)
  1162. Date: 26 Aug 1994 16:07:46 GMT
  1163. Organization: Electrical and Computer Engineering, Carnegie Mellon
  1164.  
  1165. In article <33geo0$5h3@search01.news.aol.com> bootstrap1@aol.com (Bootstrap1) writes:
  1166. >In article <DENNIS.94Aug24102539@mr2.ece.cmu.edu>, dennis@mr2.ece.cmu.edu
  1167. >(Dennis J. Ciplickas) writes:
  1168. >> I regularly use an "error exit" goto construct in my C
  1169. >> code because it's just too damn difficult to unravel yourself at each
  1170. >> point where you might need to exit.  A common example is in a routine
  1171. >> that must allocate a few different items, and if any one of them fails
  1172. >> you complain to the user and quit.  For example:
  1173. >>[code deleted]
  1174. >
  1175. >While I think it is fine to use a goto construct in a well structured way
  1176. >such as you illustrate in your example, I still never use them myself.  As
  1177. >with using continue and break in loops and return in the middle of
  1178. >functions, I find it makes the flow of a function more difficult to
  1179. >follow.  Knowing that a function starts executing at the top and falls
  1180. >straight through all the way to the bottom makes debugging and reading
  1181. >code much easier, at least for me.  And you can still avoid having to
  1182. >unravel on reaching an error conditions, as well as the dreaded "code
  1183. >waterfall" someone else mentioned, without using gotos, as the following
  1184. >edit of your sample shows
  1185. >[code removed]
  1186.  
  1187. I understand your desire to keep the code readable, but in all
  1188. honesty, the sample code you provided was difficult to read.  Not to
  1189. mention it relies on the compiler to optimize away all of the
  1190. redundant checks on the err vaiarble.
  1191.  
  1192. To the original poster: in my mind, it comes down to this.  If using a
  1193. goto will make the code MORE readable and MORE maintainable, then go
  1194. for it.  If it will obscure the flow of the code then don't.  FORTRAN
  1195. did not give programmers good methods for dealing with code structure
  1196. (e.g. break, continue, etc.), only giving them the infamous GOTO to
  1197. implement such a flow.  Misuse of GOTO ended up obscuring the program
  1198. flow.
  1199.  
  1200. If I were to go out on a limb, I'd say that improper indentation makes
  1201. code unreadable (and hence more difficult to maintain) more than the
  1202. goto construct I presented.  (Of course, FORTRAN had stringent column
  1203. requirements, too, so it was also bogus in this respect.)
  1204.  
  1205. Just my $0.02.
  1206.  
  1207. -Dennis
  1208.  
  1209. +++++++++++++++++++++++++++
  1210.  
  1211. >From Kevin.R.Boyce@gsfc.nasa.gov (Kevin R. Boyce)
  1212. Date: Fri, 26 Aug 1994 12:47:08 -0400
  1213. Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
  1214.  
  1215. In article <33jrdo$95h@search01.news.aol.com>,
  1216.  radixinc@aol.com (RadixInc) wrote:
  1217.  
  1218. >In article <33isqt$sie@search01.news.aol.com>, radixinc@aol.com (RadixInc)
  1219. >writes:
  1220. >
  1221. ><<A lot of the anti-goto sentiment comes out of Wirth's article "GOTO
  1222. >considered harmful,...>>
  1223. >
  1224. >As one polite person pointed out to me by email, the paper "GOTO
  1225. >Considered Harmful" was written be Edsger Dijkstra, not Niklaus Wirth. I
  1226. >always get them confused--they both have unpronouncable last names. I
  1227. >believe Dijkstra's paper appeared in the CACM, but I don't have it.
  1228.  
  1229. >From Jargon File 3.0.0:
  1230.  
  1231. :considered harmful: adj. Edsger W. Dijkstra's note in the
  1232.    March 1968 "Communications of the ACM", "Goto Statement
  1233.    Considered Harmful", fired the first salvo in the structured
  1234.    programming wars.  Amusingly, the ACM considered the resulting
  1235.    acrimony sufficiently harmful that it will (by policy) no longer
  1236.    print an article taking so assertive a position against a coding
  1237.    practice.  In the ensuing decades, a large number of both serious
  1238.    papers and parodies have borne titles of the form "X
  1239.    considered Y".  The structured-programming wars eventually blew
  1240.    over with the realization that both sides were wrong, but use of
  1241.    such titles has remained as a persistent minor in-joke (the
  1242.    `considered silly' found at various places in this lexicon is
  1243.    related).
  1244. -- 
  1245. Kevin      Kevin.R.Boyce@gsfc.nasa.gov
  1246. What may appear to the faint-hearted as a limitless expanse of God-forsaken wilderness is in reality a golden opportunity for ourselves, and our children, and our children's children, and the generations a-comin' to carve a new life out of the American Indian.  
  1247.       --Firesign Theatre
  1248.  
  1249. +++++++++++++++++++++++++++
  1250.  
  1251. >From walkerj@math.scarolina.edu (James W. Walker)
  1252. Date: 26 Aug 1994 17:25:30 GMT
  1253. Organization: Dept. of Mathematics, Univ. of South Carolina
  1254.  
  1255. In article <33k3rp$b4v@search01.news.aol.com>, radixinc@aol.com (RadixInc)
  1256. wrote:
  1257.  
  1258. > There's a good article in "d e v e l o p," August 1992, called "Living In
  1259. > An Exceptional World" by Sean Parent. He proposes an elegant mechanism for
  1260. > handling exceptions with macros, including clean-up and recovery. His
  1261. > technique uses macros that resolve to gotos, but it keeps the source code
  1262. > clean. I've been using these macros for a year or so, and I haven't had to
  1263. > use an actual goto since. Check it out.
  1264.  
  1265. I use those macros too.  However, I renamed his "nrequire" as "forbid".  I
  1266. find it easier to read actual English words.
  1267.  
  1268. -- 
  1269.  Jim Walker
  1270.  
  1271. +++++++++++++++++++++++++++
  1272.  
  1273. >From hanrek@cts.com (Mark Hanrek)
  1274. Date: 26 Aug 1994 18:31:38 GMT
  1275. Organization: The Information Workshop
  1276.  
  1277.  
  1278. If one is using a modern language, the "rule" to not use goto's is meaningless.
  1279.  
  1280. It was a rule meant to deter "spaghetti code", because it was so easy to
  1281. create a tangled web.  With today's languages, we create messes of a
  1282. different kind.
  1283.  
  1284. The right thing to do, regardless, is to imitate the constructs and
  1285. structuring we find in good example source code.
  1286.  
  1287. Whether we code a "break", a "try/catch", or "goto", we are doing it
  1288. because it is the appropriate thing to do.
  1289.  
  1290.  
  1291.  
  1292. Hope this helps.
  1293.  
  1294. Mark Hanrek
  1295.  
  1296. +++++++++++++++++++++++++++
  1297.  
  1298. >From urge@mcl.ucsb.edu (Scott Bronson)
  1299. Date: 27 Aug 1994 23:27:35 GMT
  1300. Organization: University of California, Santa Barbara
  1301.  
  1302. In <Jaeger-2508942242470001@slip-1-21.ots.utexas.edu> Jaeger@fquest.com (Brian Stern) writes:
  1303.  
  1304. >The fact is that memerrors aren't fatal.  there's nothing wrong with
  1305. >something like the following:
  1306.  
  1307. >   h1 = NewHandle( 10 );
  1308. >   h2 = NewHandle( 20 );
  1309. >   p1 = NewPtr( 10 );
  1310. >   p2 = NewPtr( 10 );
  1311.  
  1312. >   if ( noErr != ( err = MemError() ) ) { /* do something */ }
  1313.  
  1314.  
  1315. Well, there's nothing wrong with *your* code, but there's a serious
  1316. flaw in this technique.
  1317.  
  1318. What about this:
  1319.  
  1320. h1 = NewHandle( 30 ), h2 = NewHandle( 10 );
  1321.  
  1322. If there are 26 bytes of memory free, h2 will be a vaild handle and
  1323. MemError() is going to report noErr because the last memory allocation
  1324. succeeded.  However, h1 will be nil!  If you do your memory allocations
  1325. from smallest to largest, you will probably be OK.  However, heap
  1326. fragmentation can still cause some unexpected surprises when mixing
  1327. the allocation of pointers and handles.
  1328.  
  1329. So, even though this works, I hope that no programmers rely on it
  1330. unless they're sure they know EXACTLY what they're doing.  Personally,
  1331. I shun it--too much analysis on noncritical parts of my code gives me
  1332. a bad case of programmer burnout.
  1333.  
  1334.     - Scott                (urge@mcl.mcl.ucsb.edu)
  1335.  
  1336.  
  1337. +++++++++++++++++++++++++++
  1338.  
  1339. >From bb@lightside.com (Bob Bradley)
  1340. Date: Sat, 27 Aug 1994 02:24:40 -0800
  1341. Organization: SS Software Inc.
  1342.  
  1343. In <Jaeger-2508942242470001@slip-1-21.ots.utexas.edu> Jaeger@fquest.com
  1344. (Brian Stern) writes:
  1345.  
  1346. >The fact is that memerrors aren't fatal.  there's nothing wrong with
  1347. >something like the following:
  1348. >   h1 = NewHandle( 10 );
  1349. >   h2 = NewHandle( 20 );
  1350. >   p1 = NewPtr( 10 );
  1351. >   p2 = NewPtr( 10 );
  1352.  
  1353. >   if ( noErr != ( err = MemError() ) ) { /* do something */ }
  1354.  
  1355. If you don't have enough memory for the first one, you're still going to
  1356. try all the others. I would check for both the handle not being NULL and
  1357. that MemError() did not return anything but, noErr after each call to
  1358. NewHandle(...).
  1359.  
  1360. +++++++++++++++++++++++++++
  1361.  
  1362. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University)
  1363. Date: 29 Aug 94 16:58:57 +1200
  1364. Organization: University of Waikato, Hamilton, New Zealand
  1365.  
  1366. In article <300.310.uupcb@digitec.co.za>, steven.webber@digitec.co.za (Steven Webber)  writes:
  1367. >
  1368. > Do you use goto's in your code?
  1369.  
  1370. Nope. I use Modula-2, which doesn't have goto's.
  1371.  
  1372. > Do you think using Goto's is a bad or good idea?
  1373.  
  1374. I think overall they're a poor idea, because it's so hard to spot any mistakes
  1375. that you make with them. But then, I also think exceptions are a poor idea--I
  1376. like being able to see the control flow in my program at a glance.
  1377.  
  1378. Modula-2 has this LOOP construct, which is basically an endless loop, within
  1379. which you have to put EXIT statements to exit, eg:
  1380.  
  1381.     LOOP
  1382.       (* do some cool stuff *)
  1383.     IF ExitCondition1 THEN
  1384.         EXIT
  1385.     END (*IF*);
  1386.       (* do more cool stuff *)
  1387.     IF ExitCondition2 THEN
  1388.         EXIT
  1389.     END (*IF*)
  1390.       (* and so on *)
  1391.     END (*LOOP*)
  1392.  
  1393. Modula-2 also has the usual WHILE, REPEAT and FOR loops, just like Pascal,
  1394. but I find that 90% of my loops are LOOP loops. This is because I frequently
  1395. need to check for error returns from system calls, and abort the loop if I
  1396. get one.
  1397.  
  1398. Furthermore, I frequently encounter the need to check for error returns during
  1399. a linear sequence of operations, not necessarily in a loop, and abort the
  1400. sequence at the point I hit the error. This gave me the idea for a loop-
  1401. statement-that-doesn't-loop. I fake this in Modula-2 something like this:
  1402.  
  1403.     InitStorage;
  1404.     LOOP (*once*)
  1405.     DoOSCall1;
  1406.     IF Err <> noErr THEN
  1407.         EXIT
  1408.     END (*IF*);
  1409.     DoOSCall2;
  1410.     IF Err <> noErr THEN
  1411.         EXIT
  1412.     END (*IF*);
  1413.       (* all done *)
  1414.     EXIT
  1415.     END (*LOOP*);
  1416.     DisposeStorage
  1417.  
  1418. "InitStorage" initializes all pointers to NIL, marks files as unopened etc,
  1419. and "DisposeStorage" goes through and disposes of all allocated pointers,
  1420. closes all open files and so on. By strictly adhering to this layout, it's
  1421. always easy to see where control will go in all situations.
  1422.  
  1423. Thought for the week: Testing is of limited help if you can't write correct
  1424. code to begin with.
  1425.  
  1426. Lawrence D'Oliveiro                       fone: +64-7-856-2889
  1427. Info & Tech Services Division              fax: +64-7-838-4066
  1428. University of Waikato            electric mail: ldo@waikato.ac.nz
  1429. Hamilton, New Zealand    37^ 47' 26" S, 175^ 19' 7" E, GMT+12:00
  1430.  
  1431. +++++++++++++++++++++++++++
  1432.  
  1433. >From dbenn@leven.appcomp.utas.edu.au (David Benn)
  1434. Date: Tue, 30 Aug 94 02:32:39 GMT
  1435. Organization: University of Tasmania
  1436.  
  1437. I don't know if anyone has mentioned this during the course of this thread,
  1438. but "The C Users Journal", June 1994 has an article called "Control
  1439. Structures" which discusses many of the issues that have cropped up in this
  1440. discussion.
  1441.  
  1442. The article is in on page 81 and is by Chuck Allison.
  1443.  
  1444. Rgds,
  1445.  
  1446. David Benn
  1447.  
  1448. -- 
  1449. D.Benn@appcomp.utas.edu.au - David Benn. University of Tasmania at Launceston.
  1450. The effort to understand the universe is one of the few things that lifts
  1451. human life above the level of farce, and gives it some of the grace of 
  1452. tragedy. (Steven Weinberg)
  1453.  
  1454. +++++++++++++++++++++++++++
  1455.  
  1456. >From dowdy@apple.com (Tom Dowdy)
  1457. Date: Wed, 31 Aug 1994 00:25:26 GMT
  1458. Organization: Apple Computer, Inc.
  1459.  
  1460. In article <33k3rp$b4v@search01.news.aol.com>, radixinc@aol.com (RadixInc)
  1461. wrote:
  1462.  
  1463. > In article <DENNIS.94Aug24102539@mr2.ece.cmu.edu>, dennis@mr2.ece.cmu.edu
  1464. > (Dennis J. Ciplickas) wrote:
  1465. > << I regularly use an "error exit" goto construct in my C code because
  1466. > it's just too damn difficult to unravel yourself at each point where you
  1467. > might need to exit.>>
  1468. > There's a good article in "d e v e l o p," August 1992, called "Living In
  1469. > An Exceptional World" by Sean Parent. He proposes an elegant mechanism for
  1470. > handling exceptions with macros, including clean-up and recovery. His
  1471. > technique uses macros that resolve to gotos, but it keeps the source code
  1472. > clean. I've been using these macros for a year or so, and I haven't had to
  1473. > use an actual goto since. Check it out.
  1474.  
  1475. I'd like to put another vote down for this style of handling...
  1476.  
  1477. Sean wrote these macros for us a *loooong* time ago, and they are
  1478. used in various parts of system software, including just about
  1479. all of the GX printing code.  In fact, a version of Exceptions.h
  1480. ships with the GX includes because we couldn't imagine the work
  1481. involved in un-"nrequire"ing the sample driver code.
  1482.  
  1483. These macros take a small amount to get used to, but once you've
  1484. got it, you'll find that you just about never fail to include some
  1485. level of error handling in your code (even if it's just simple
  1486. cleanup-exit type).
  1487.  
  1488. -- 
  1489.  Tom Dowdy                  Internet: dowdy@apple.COM
  1490.  Apple Computer MS:302-3KS  UUCP: {sun,voder,amdahl,decwrl}!apple!dowdy
  1491.  1 Infinite Loop            AppleLink: DOWDY1
  1492.  Cupertino, CA 95014       
  1493.  "The 'Ooh-Ah' Bird is so called because it lays square eggs."
  1494.  
  1495. +++++++++++++++++++++++++++
  1496.  
  1497. >From h+@nada.kth.se (Jon W{tte)
  1498. Date: Fri, 02 Sep 1994 09:18:45 +0200
  1499. Organization: Royal Institute of Something or other
  1500.  
  1501. In article <dowdy-3008941725260001@17.202.68.12>,
  1502. dowdy@apple.com (Tom Dowdy) wrote:
  1503.  
  1504. >all of the GX printing code.  In fact, a version of Exceptions.h
  1505. >ships with the GX includes because we couldn't imagine the work
  1506. >involved in un-"nrequire"ing the sample driver code.
  1507.  
  1508. Yes, and during the beta cycle, I pointed out that the name 
  1509. "Exceptions.h" collides with the same file name in the Think 
  1510. Class Library, and suggested changing the name to 
  1511. GXExceptions.h, since the Think Class Library is probably the 
  1512. most used Mac application framework.
  1513.  
  1514. THIS WAS PROMISED!
  1515.  
  1516. Of course it didn't happen.
  1517.  
  1518. Cheers,
  1519.  
  1520.                     / h+
  1521.  
  1522.  
  1523. --
  1524.   Jon W‰tte (h+@nada.kth.se), Hagagatan 1, 113 48 Stockholm, Sweden
  1525.  
  1526.   Reality exists only in your imagination.
  1527.  
  1528.  
  1529. ---------------------------
  1530.  
  1531. >From jcd7106@tamsun.tamu.edu (John C. Daub)
  1532. Subject: Need help with saving-writing structs to a file.
  1533. Date: 3 Sep 1994 16:08:55 -0500
  1534. Organization: Texas A&M University, College Station
  1535.  
  1536.  
  1537. Hi :)  I'm having some trouble with trying to write stuff to a file.
  1538.  
  1539. My program is, essentially, a database.  The information the user enters
  1540. is saved in a struct (and linked list).  To illustrate, here's the
  1541. struct:
  1542.  
  1543. struct SongInfo
  1544. {
  1545.     Str255        title;
  1546.     Str255        artist;
  1547.     unsigned short    songTime;
  1548.     short        tempo;
  1549.     Boolean        isOriginal;
  1550.     Str255        songComments;
  1551.     Boolean        fitsGenCrit;
  1552.     short        listGen;
  1553.     short        menuItem;
  1554.     struct SongInfo *next, *prev;
  1555. };
  1556. typedef struct SongInfo SongInfo *SongInfoPtr;
  1557.  
  1558.  
  1559. >From what i can tell with my entering/editing functions, there seems
  1560. to be no problems with entering information nor with editing that
  1561. information (and even removing an entry).
  1562.  
  1563. But, when i try to save this information/structs/linked-list to a file,
  1564. I get all sorts of weird things (I open up the data fork, raw, in 
  1565. something like BBEdit Lite).
  1566.  
  1567. Here's my basic routine for trying to save:
  1568.  
  1569. (skip all the stuff about FSOpen(), Create(), SetEOF(), SetFPos(), etc).
  1570.  
  1571.  
  1572.     curPtr = gFirstSongInfoPtr;
  1573.  
  1574.     err = FSWrite( fRefNum, &(sizeof(SongInfo)), &curPtr );
  1575.     if ( err != noErr )
  1576.         return( err );
  1577.  
  1578.     curPtr = curPtr->next;
  1579.  
  1580. I also have a global to hold the offset...start at the beginning of the
  1581. file, add the one song, increase the offset global by sizeof(SongInfo),
  1582. then go back and repeat this until you get to the end of it all.
  1583.  
  1584. Now, i wonder if i'm doing something wrong with checking for curPtr->next = NIL
  1585. and then letting this while loop for the FSWrite() go too long, or what.
  1586.  
  1587. I've seen sample source that does this same sort of thing, and it works
  1588. fine there, but why not here?
  1589.  
  1590. One time, i ended up with parts of the database info, then i got half of
  1591. a source file in there (don't ask me how).
  1592.  
  1593. Could it be something to do with using Pascal strings?  Would it help
  1594. to perhaps save each part of the struct on it's own...like convert
  1595. the pascal strings to C strings (read them into an array or something),
  1596. enter that, then move to the next struct member, write that, then the
  1597. next, write that...each time increasing the offest by sizeof(variable)?
  1598.  
  1599. Any help in writing structs to a file would be greatly appreaciated :)
  1600.  
  1601. pleae email to:  hsoi@tamu.edu
  1602.  
  1603. thanx, John
  1604.  
  1605. +++++++++++++++++++++++++++
  1606.  
  1607. >From decartwr@newstand.syr.edu (Dana Cartwright 3rd)
  1608. Date: 3 Sep 1994 22:10:46 GMT
  1609. Organization: Syracuse University, Syracuse NY, USA
  1610.  
  1611. John C. Daub (jcd7106@tamsun.tamu.edu) wrote:
  1612.  
  1613. : But, when i try to save this information/structs/linked-list to a file,
  1614. : I get all sorts of weird things (I open up the data fork, raw, in 
  1615. : something like BBEdit Lite).
  1616.  
  1617. I try to avoid writing structs directly to files.  For at least two
  1618. reasons.  First, structs are compiled differently by different
  1619. compilers...that is, the compiler is free to add padding here and
  1620. there in structs to maintain data alignment.  So if you write a
  1621. struct to a file, there's a goodly chance you're writing more bytes
  1622. than you might imagine just from a visual inspection of the
  1623. struct, and if you re-compile your code with a different compiler
  1624. (even from the same company), you might no longer be able to read
  1625. back your older files.
  1626.  
  1627. Second, if you want any kind of cross-platform compatibility, you
  1628. have "little-endian" versus "big-endian" (basically, the order of
  1629. bytes within multi-byte numbers) issues, which are most easily 
  1630. dealt with by exercising VERY tight control over the way data is
  1631. read/written.  Hard to do that when you let the compiler dictate 
  1632. how your data is laid out.
  1633.  
  1634. I'm guessing here, but I would not be at all surprised if structs
  1635. were sometimes different on 68K versus PPC compilers.
  1636.  
  1637. So one way to "solve" your problem would be to more precisely control
  1638. your file format, which would also probably resolve some of the
  1639. problems you mention in your post.
  1640.  
  1641.  
  1642. +++++++++++++++++++++++++++
  1643.  
  1644. >From afcjlloyd@aol.com (AFC JLloyd)
  1645. Date: 3 Sep 1994 18:50:03 -0400
  1646. Organization: America Online, Inc. (1-800-827-6364)
  1647.  
  1648. In article <34aol7$p4u@tamsun.tamu.edu>, jcd7106@tamsun.tamu.edu (John C.
  1649. Daub) writes:
  1650.  
  1651. >Hi :)  I'm having some trouble with trying to write stuff to a file.
  1652. >
  1653. >[ some stuff omitted ]
  1654. >
  1655. >Here's my basic routine for trying to save:
  1656. >
  1657. >(skip all the stuff about FSOpen(), Create(), SetEOF(), SetFPos(), etc).
  1658. >
  1659. > curPtr = gFirstSongInfoPtr;
  1660. >
  1661. > err = FSWrite( fRefNum, &(sizeof(SongInfo)), &curPtr );
  1662.  
  1663. This FSWrite statement has two problems.  You should rewrite it like this:
  1664.  
  1665. long bytesWritten = sizeof(SongInfo);
  1666. err = FSWrite( fRefNum, &bytesWritten, curPtr );
  1667.  
  1668. It's not a good idea to pass an address of a compiler generated constant
  1669. to a function that will write into the address.  And if you want to write
  1670. out a set of bytes starting at an address, pass the
  1671. value of that address, not the address of a pointer that points to the
  1672. desired address.
  1673.  
  1674. Jim Lloyd
  1675. afcjlloyd@aol.com
  1676.  
  1677.  
  1678. +++++++++++++++++++++++++++
  1679.  
  1680. >From bb@lightside.com (Bob Bradley)
  1681. Date: Fri, 02 Sep 1994 17:42:28 -0800
  1682. Organization: SS Software Inc.
  1683.  
  1684. In article <34as96$hh3@newstand.syr.edu>, decartwr@mailbox.syr.edu wrote:
  1685.  
  1686. > I try to avoid writing structs directly to files.  For at least two
  1687. > reasons.  First, structs are compiled differently by different
  1688. > compilers...that is, the compiler is free to add padding here and
  1689. > there in structs to maintain data alignment.  So if you write a
  1690. > struct to a file, there's a goodly chance you're writing more bytes
  1691. > than you might imagine just from a visual inspection of the
  1692. > struct, and if you re-compile your code with a different compiler
  1693. > (even from the same company), you might no longer be able to read
  1694. > back your older files.
  1695.  
  1696. I wasn't aware of the problems that can arise when reading/writing structs
  1697. to a file, how can I change my code to fix the problems?
  1698.  
  1699. I typically have something like:
  1700.  
  1701. typedef struct
  1702. {
  1703.     short               shortNumber;
  1704.     FSSpec              spec;
  1705.  
  1706. }   MyRecord;
  1707.  
  1708. And I write that whole structure to disk. In order to do things correctly
  1709. (to elminate the problems mentioned above) do I have to write each field
  1710. of the structure individually? I frequently have structures inside of
  1711. structures and I also save some Apple defined structures to disk, is there
  1712. any way to fix the problem when you don't actually know the format of the
  1713. structure (ie. I wouldn't be able to save each individual field)?
  1714.  
  1715. +++++++++++++++++++++++++++
  1716.  
  1717. >From vanderHarg@DIMES.TUDelft.NL (Arthur van der Harg)
  1718. Date: Sun, 4 Sep 1994 12:16:54 GMT
  1719. Organization: Hardly
  1720.  
  1721. In article <34as96$hh3@newstand.syr.edu>, decartwr@mailbox.syr.edu wrote:
  1722.  
  1723. > I'm guessing here, but I would not be at all surprised if structs
  1724. > were sometimes different on 68K versus PPC compilers.
  1725.  
  1726. Or between differently compiled versions on 68k. SC++ 7.x lets you choose
  1727. field alignment to 1, 2 or 4-byte boundaries. So if you have a field with
  1728. an odd or non-mod4 number of bytes, the structure will be aligned
  1729. differently for different compiler *settings*, let alone different
  1730. compilers or different architectures.
  1731.  
  1732. Arthur
  1733.  
  1734. -- 
  1735. This message (c) Arthur van der Harg <vanderHarg@DIMES.TUDelft.nl>
  1736.  
  1737. +++++++++++++++++++++++++++
  1738.  
  1739. >From parkb@bigbang.Stanford.EDU (Brian Park)
  1740. Date: 5 Sep 1994 07:31:25 GMT
  1741. Organization: Stanford University
  1742.  
  1743. Dana Cartwright 3rd <decartwr@mailbox.syr.edu> wrote:
  1744. >I try to avoid writing structs directly to files.  For at least two
  1745. >reasons.  First, structs are compiled differently by different
  1746. >compilers...
  1747. [...]
  1748. >Second, if you want any kind of cross-platform compatibility, you
  1749. >have "little-endian" versus "big-endian" 
  1750. [...]
  1751.  
  1752. Resource Manager writes structures to files... doesn't it?
  1753.  
  1754. --
  1755. Brian Park
  1756. parkb@bigbang.stanford.edu
  1757.  
  1758. +++++++++++++++++++++++++++
  1759.  
  1760. >From hanrek@cts.com (Mark Hanrek)
  1761. Date: Mon, 5 Sep 1994 08:08:27 GMT
  1762. Organization: The Information Worskhop
  1763.  
  1764. In article <34aol7$p4u@tamsun.tamu.edu>, jcd7106@tamsun.tamu.edu (John C.
  1765. Daub) wrote:
  1766.  
  1767. > Hi :)  I'm having some trouble with trying to write stuff to a file.
  1768. > My program is, essentially, a database.  The information the user enters
  1769. > is saved in a struct (and linked list).  
  1770. >
  1771. > [ stuff deleted ]
  1772. > From what i can tell with my entering/editing functions, there seems
  1773. > to be no problems with entering information nor with editing that
  1774. > information (and even removing an entry).
  1775. > But, when i try to save this information/structs/linked-list to a file,
  1776. > I get all sorts of weird things (I open up the data fork, raw, in 
  1777. > something like BBEdit Lite).
  1778.  
  1779. John,
  1780.  
  1781. You didn't mention exactly how you are determining that something is wrong.  
  1782.  
  1783. Do things appear "wierd" only when you look at it with BBEdit?  It should
  1784. look wierd because you are writing binary stuff, no to mention that the
  1785. unused portions of p-strings and any fields that have not had anything
  1786. stored in them will have random values in them.  You'll want to use a hex
  1787. editor like HexEdit.
  1788.  
  1789. If you mean "wierd things when you read it back in"... of course, you
  1790. cannot expect the links ( next/previous ) to be correct.  You will want to
  1791. read in a record's worth from disk, but copy to good stuff into a brand
  1792. new record you've just created, just as you do when entering a new
  1793. record.  I figure you know this, but just in case. :)
  1794.  
  1795. Also, perhaps you should use FlushVol() as well, to ensure that all of
  1796. your file writes actually get written to disk.
  1797.  
  1798. The gist of my message here is that so often, there isn't a problem with
  1799. what we are examining, but with the methods we are using to examine
  1800. things.  That's not a new comet you've discovered, it is just a dead gnat
  1801. stuck to the lens of the telescope. :)  I've been bit by this one many
  1802. times ( but not lately :).
  1803.  
  1804. Just maybe one of the above will help to "jiggle something free" for ya.
  1805.  
  1806.  
  1807. Mark Hanrek
  1808.  
  1809. +++++++++++++++++++++++++++
  1810.  
  1811. >From howard@netcom.com (Howard Berkey)
  1812. Date: Mon, 5 Sep 1994 17:59:13 GMT
  1813. Organization: Psychonaut Foundation
  1814.  
  1815.  
  1816. Short answer:  look in a computer science textbook.
  1817.  
  1818. Non-snide answer:
  1819.  
  1820. Essentially the best way to write a data structure to a file is to first 
  1821. flatten it into an array, changing the pointers to array indices.  For 
  1822. example, to write a binary tree, make the root node element 0 of the array, 
  1823. and change its left and right node pointers to 1 and 2, respectively.  Then 
  1824. put the nodes they pointed to into those array elements.  Go to array element 
  1825. 1 and repeat.  And so on.  Reading back in is easy.  I'll append some code
  1826. at the end of the message.
  1827.  
  1828. A list is even easier.
  1829.  
  1830. Now, one thing to make sure of is that you are using the same structure
  1831. alignment between builds.  I stupidly bit myself the other day by not 
  1832. checking the project prefs in CodeWarrior the other day... the app I had
  1833. generating the file was set to 68K struct alignment, and the one reading 
  1834. it in was set to 68K 4-byte.  This caused all sorts of problems.
  1835.  
  1836. Luckily on the mac you don't need to worry about the endian-ness of the 
  1837. machine.  
  1838.  
  1839. Anyway, here's a quick example in C++.  I cut and pasted this from 
  1840. something in progress so it may contain bugs but it will get the general 
  1841. idea across (Assume that CPolygon is defined somewhere else and knows how 
  1842. to write itself):
  1843.  
  1844.  
  1845. class CBSPTree {
  1846.  
  1847. private:
  1848.       CPolygon *rootPoly;
  1849.       CBSPTree *backChild;
  1850.       CBSPTree *frontChild;
  1851.       int nodes;
  1852.       
  1853.       struct treeFileFormat 
  1854.       {
  1855.          CPolygon *thePoly;
  1856.          int       frontChild;
  1857.          int       backChild;
  1858.          int       nodes;
  1859.       };
  1860.          
  1861. public:
  1862.       
  1863.       void flattenSubtree(int current, int nextFree, struct treeFileFormat
  1864. *theArray);
  1865.  
  1866.       void writeTree(short treeFile);
  1867.       void readTree(short treeFile);
  1868.       
  1869. };
  1870.  
  1871.  
  1872.  
  1873. void CBSPTree :: writeTree(short treeFile)
  1874. {
  1875.    long inOutCount=(long) sizeof(int);
  1876.    int i;
  1877.    treeFileFormat *theArray;
  1878.    
  1879.    theArray = new treeFileFormat[this->nodes];
  1880.       
  1881.    flattenSubtree(0, 1, theArray);
  1882.             
  1883.    i=this->nodes + 1;
  1884.    FSWrite(treeFile,&inOutCount,&i);   
  1885.  
  1886.    for(i=0;i<=this->nodes;i++)
  1887.    {
  1888.       theArray[i].thePoly->writePoly(treeFile);
  1889.       FSWrite(treeFile,&inOutCount, &theArray[i].nodes);   
  1890.       FSWrite(treeFile,&inOutCount,&theArray[i].frontChild);   
  1891.       FSWrite(treeFile,&inOutCount,&theArray[i].backChild);   
  1892.    }
  1893. }
  1894.  
  1895.  
  1896.  
  1897. void CBSPTree :: flattenSubtree(int current, int nextFree, treeFileFormat
  1898. *theArray)
  1899. {      
  1900.        int myIndex;
  1901.        
  1902.        myIndex=current;
  1903.        
  1904.         if(this->rootPoly != NULL)
  1905.         {    
  1906.                 theArray[myIndex].thePoly=this->rootPoly;
  1907.                 theArray[myIndex].nodes=this->nodes;
  1908.                 if(this->frontChild != NULL)
  1909.                 {
  1910.                      theArray[myIndex].frontChild=nextFree++;
  1911.                      current=theArray[myIndex].frontChild;
  1912.                      this->frontChild->flattenSubtree(current,
  1913. nextFree,            theArray);
  1914.  
  1915.                 }
  1916.                 else
  1917.                 {
  1918.                      theArray[myIndex].frontChild=-1;
  1919.                 }
  1920.                 
  1921.                 if(this->backChild != NULL)
  1922.                 {
  1923.                      theArray[myIndex].backChild=nextFree++;
  1924.                      current=theArray[myIndex].backChild;
  1925.                      this->backChild->flattenSubtree(current, nextFree,
  1926. theArray);
  1927.  
  1928.                 }
  1929.                 else
  1930.                 {
  1931.                       theArray[myIndex].backChild=-1;
  1932.                 }
  1933.  
  1934.         }
  1935. }
  1936.  
  1937.  
  1938. void CBSPTree :: readTree(short treeFile)
  1939. {
  1940.    struct treeFileFormat *treeArray;
  1941.    CBSPTree *BSPArray, *tmpTree;
  1942.    long inOutCount=(long) sizeof(int);
  1943.    int i, count;
  1944.     
  1945.  
  1946.    SetFPos(treeFile, fsFromStart, 0);
  1947.    FSRead(treeFile, &inOutCount, &count);
  1948.    
  1949.    treeArray=new treeFileFormat[count];
  1950.    BSPArray=new CBSPTree[count];
  1951.       
  1952.    for(i=0;i<count;i++) 
  1953.    {
  1954.       treeArray[i].thePoly = new CPolygon;
  1955.       treeArray[i].thePoly->readPoly(treeFile);
  1956.       FSRead(treeFile, &inOutCount, &treeArray[i].nodes);
  1957.       FSRead(treeFile, &inOutCount, &treeArray[i].frontChild);
  1958.       FSRead(treeFile, &inOutCount, &treeArray[i].backChild);
  1959.    }
  1960.  
  1961.    for(i=0;i<count;i++)
  1962.     {
  1963.       
  1964.       BSPArray[i].rootPoly=treeArray[i].thePoly;
  1965.       BSPArray[i].nodes=treeArray[i].nodes;
  1966.       if(treeArray[i].frontChild != -1) BSPArray[i].frontChild 
  1967.                                        = &BSPArray[treeArray[i].frontChild];
  1968.       if(treeArray[i].backChild != -1) BSPArray[i].backChild 
  1969.                                        =
  1970. &BSPArray[treeArray[i].backChild];                                    
  1971.       
  1972.     }
  1973.     
  1974.    *this=BSPArray[0];   
  1975.  
  1976. }
  1977.  
  1978. -- 
  1979. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  1980. Howard Berkey                                     howard@netcom.com
  1981. Segmentation Fault (core dumped)
  1982.  
  1983. ---------------------------
  1984.  
  1985. >From wdh@fresh.com (Bill Hofmann)
  1986. Subject: PBCatSearch-catChangedErr
  1987. Date: Sat, 3 Sep 1994 21:41:58 GMT
  1988. Organization: Fresh Software
  1989.  
  1990. OK, I've got PBCatSearch working, it's a little arcane, but what isn't
  1991. nowadays.    I use the results to scan certain files for certain resources
  1992. (ie, I do an FSpOpenResFile on the files returned).  But here's the
  1993. problem: AutoDoubler (and I suppose other utils of that ilk) modify the
  1994. catalog when I open the files, causing PBCatSearch to return catChangedErr
  1995. (-1304) on the next call to it.
  1996.  
  1997. So far, the only real solution seems to be a real humongous search (ie, so
  1998. that I only have to call PBCatSearch once).  Am I right?
  1999. -Bill
  2000. -- 
  2001. Bill Hofmann                                   wdh@fresh.com
  2002. Fresh Software and Instructional Design        voice: +1 510 524 0852
  2003. 1640 San Pablo Ave #C Berkeley CA 94702 USA    fax:   +1 510 524 0853
  2004.  
  2005. +++++++++++++++++++++++++++
  2006.  
  2007. >From jumplong@aol.com (Jump Long)
  2008. Date: 4 Sep 1994 12:01:05 -0400
  2009. Organization: America Online, Inc. (1-800-827-6364)
  2010.  
  2011. In article <wdh-0309941441580001@wdh.slip.netcom.com>, wdh@fresh.com (Bill
  2012. Hofmann) writes:
  2013.  
  2014. >OK, I've got PBCatSearch working, it's a little arcane, but what isn't
  2015. >nowadays.    I use the results to scan certain files for certain
  2016. resources
  2017. >(ie, I do an FSpOpenResFile on the files returned).  But here's the
  2018. >problem: AutoDoubler (and I suppose other utils of that ilk) modify the
  2019. >catalog when I open the files, causing PBCatSearch to return
  2020. catChangedErr
  2021. >(-1304) on the next call to it.
  2022. >
  2023. >So far, the only real solution seems to be a real humongous search (ie,
  2024. so
  2025. >that I only have to call PBCatSearch once).  Am I right?
  2026.  
  2027. You're right, you're best off finding all of your matches and then
  2028. processing them after the matches are found. However, this makes it
  2029. impossible to let the user cancel a long search -- you need to weigh that
  2030. against the need to get all matches.
  2031.  
  2032. BTW: Any call that writes to an HFS volume will result in a catSearchErr.
  2033. The HFS file system is a little brain dead in this respect because it
  2034. really only needs to return catSearchErr if the *catalog* changes, not
  2035. *any* write to the volume. Since the AppleShare and File Sharing file
  2036. servers use HFS's CatSearch to search on the server Macintosh, this makes
  2037. searches on AppleShare volumes fail with afpCatalogChanged even more often
  2038. (in which case, the error cannot be ignored and the search cannot be
  2039. resumed) because there will likely be multiple writers on an AppleShare
  2040. volume. I guess I should try to get HFS's CatSearch problems all fixed in
  2041. the next System Update...
  2042.  
  2043. - Jim Luther
  2044.  
  2045. ---------------------------
  2046.  
  2047. >From JFN@cmq.qc.ca (Jean-Francois Nadeau)
  2048. Subject: PixToPic
  2049. Date: 05 Sep 1994 14:48:08 GMT
  2050. Organization: Club Macintosh de Quebec
  2051.  
  2052. Hello!
  2053.  
  2054. How i can transform a PICT resource in a PixMapHandle?
  2055.  
  2056. Thanks!
  2057.  
  2058. JFN@cmq.upc.qc.ca
  2059. - -----------------------------------------------------------
  2060. Synapse -- Le serveur telematique du Club Macintosh de Quebec
  2061. vox: 418.527.0250    fax: 418.527.9304    net: info@cmq.qc.ca
  2062. - -----------------------------------------------------------
  2063.  
  2064. +++++++++++++++++++++++++++
  2065.  
  2066. >From Dmitry Boldyrev <dmitry@atlas.chem.utah.edu>
  2067. Date: 5 Sep 1994 21:49:03 GMT
  2068. Organization: University of Utah
  2069.  
  2070. In article <65502.4681425@cmq.cmq.qc.ca> Jean-Francois Nadeau, JFN@cmq.qc.ca
  2071. writes:
  2072. >Hello!
  2073. >
  2074. >How i can transform a PICT resource in a PixMapHandle?
  2075. >
  2076. >Thanks!
  2077.  
  2078. Hmm.. It shouldn't be very hard.. 
  2079. void CiconToPixmap(short res_id, PixMapPtr thebitmap)
  2080. {
  2081.     CIconHandle                theicon;
  2082.     short                    right, bottom;
  2083.     unsigned long            offRowBytes, sizeOfmap;
  2084.     sysinfo                    system;
  2085.     Ptr                        offBaseAddr = nil;
  2086.     Rect                    wbounds;
  2087.     
  2088.     GWorldPtr                 currPort;   
  2089.     GDHandle                 currDev;       
  2090.     short                     err;                 
  2091.     static Rect             dOffBounds;        // Bounds of OffScreen Graphics                                                    //
  2092. World
  2093.     static GWorldPtr         gMyOffG;        // Pointer to OffScreen Graphics World
  2094.     Boolean                    gblockAlloc;    // Variable to check the successful memoryblock
  2095. allocation
  2096.  
  2097.     
  2098.     InitSysinfo( &system );    
  2099.     theicon = GetCIcon( res_id );    
  2100.     right = ( (**theicon).iconBMap ).bounds.right;
  2101.     bottom =  ( (**theicon).iconBMap ).bounds.bottom;
  2102.     SetRect( &wbounds, 0, 0, GameResHr, GameResVr );
  2103.     SetRect( &dOffBounds, 0, 0, right, bottom );
  2104.  
  2105.     GetGWorld( &currPort, &currDev );        // Build Offscreen Graphics world
  2106.     err = NewGWorld( &gMyOffG, 0, &dOffBounds, nil, nil, 0 ); // Create Offscreen
  2107. Graphics worl
  2108.     if ( err != noErr )
  2109.     {
  2110.         /* ... */
  2111.     }
  2112.  
  2113.     // Lock down Pixels that we are drawing to so that memory will not
  2114.     // move
  2115.     gblockAlloc = LockPixels (gMyOffG->portPixMap);
  2116.     
  2117.     if ( !gblockAlloc )
  2118.     {
  2119.         /* ... */
  2120.     }
  2121.     
  2122.     // Setup drawing area to be our offscreen graphics world
  2123.     
  2124.     SetGWorld (gMyOffG, nil);
  2125.     
  2126.     //The drawing area
  2127.     
  2128.     PlotCIcon( &dOffBounds, theicon );
  2129.     
  2130.     // Done drawing, now reset Port etc.
  2131.  
  2132.     SetGWorld (currPort, currDev);
  2133.  
  2134.     // Initialize the PixMap for copying
  2135.     
  2136.     offRowBytes = ( ( ( system.PixelDepth * right ) + 31 ) / 32 ) * 4;
  2137.     sizeOfmap = bottom * offRowBytes;                                    
  2138.     offBaseAddr = NewPtr( sizeOfmap );
  2139.     if ( offBaseAddr = nil )
  2140.     {
  2141.         /* ... */
  2142.     }
  2143.  
  2144.  
  2145.     printf( "%d\n", offRowBytes );
  2146.     while( !Button() ){}
  2147.     thebitmap->baseAddr = offBaseAddr;
  2148.     thebitmap->rowBytes = offRowBytes;
  2149.     thebitmap->bounds = (**theicon).iconPMap.bounds;
  2150.     BlitPixie( *gMyOffG->portPixMap, thebitmap, &(**theicon).iconPMap.bounds,
  2151. &thebitmap->bounds, &wbounds ); 
  2152.     UnlockPixels( gMyOffG->portPixMap );
  2153. }
  2154.  
  2155.  
  2156. Oh, btw, use CopyBits instead of BlitPixie.. easy to modify..
  2157.  
  2158. Dmitry
  2159. (A friend of mine wrote it.. His name is John Whited)
  2160.  
  2161. +++++++++++++++++++++++++++
  2162.  
  2163. >From gurgle@dnai.com (Pete Gontier)
  2164. Date: Mon, 05 Sep 1994 16:27:52 -0800
  2165. Organization: Integer Poet Software
  2166.  
  2167. In article <65502.4681425@cmq.cmq.qc.ca>, JFN@cmq.qc.ca wrote:
  2168.  
  2169. > How i can transform a PICT resource in a PixMapHandle?
  2170.  
  2171. This question, puzzlingly, comes up pretty often, even though it has a
  2172. fairly obvious one-word answer:
  2173.  
  2174.     DrawPicture
  2175.  
  2176. There must be something about the topic that's inherently confusing, or it
  2177. wouldn't come up so often. Of course, you have to have a pixel map lying
  2178. around, but sample code for that is easy enough to find; here is the
  2179. canonical reference:
  2180.  
  2181.     ftp://ftp.apple.com/dts/mac/tn/quickdraw.qd/qd-13-principia-off-screen.hqx
  2182.  
  2183. I have also posted some sample code for TCL 1.1.3, called 'CPixMap'.
  2184.  
  2185.     ftp://ftp.dnai.com/users/gurgle/CPixMap.sit.bin
  2186.  
  2187. Now, you could be talking about grabbing a pixel map and putting it into a
  2188. picture. That has a three-word answer:
  2189.  
  2190.     OpenPicture
  2191.     CopyBits
  2192.     ClosePicture
  2193.  
  2194. In either case, you'll be needing a pixel map. :-)
  2195.  
  2196. -- 
  2197.  
  2198.  Pete Gontier // Integer Poet Software // gurgle@dnai.com
  2199.  
  2200.  "The need to be (or appear to be) sophisticated pervades the very
  2201.  atmosphere in which we, the Magazine Reading Class, move."
  2202.                   -- Eliis Weiner, Spy Magazine, 9/94
  2203.  
  2204. ---------------------------
  2205.  
  2206. >From bb@lightside.com (Bob Bradley)
  2207. Subject: Slashed Progress Bar
  2208. Date: Sat, 27 Aug 1994 02:25:15 -0800
  2209. Organization: SS Software Inc.
  2210.  
  2211. I'm trying to implement the Slashed Progress Bar just like Anarchie's when
  2212. it's trying to connect and similar to the Finder's when it's doing
  2213. something that it doesn't know how long it will take.
  2214.  
  2215. I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2216. the Finder does. I'd like to do something similar to Anarchie but, am not
  2217. sure how. Anyone have any sample source or suggestions?
  2218.  
  2219. I'm writing a simple progress bar CDEF that will do progress bars ike
  2220. normal and support that moving slashed "Not sure how long it will take
  2221. but, I'm trying" look which I why I want to stay away from PICT's.
  2222.  
  2223. +++++++++++++++++++++++++++
  2224.  
  2225. >From trygve@netcom.com (Trygve Isaacson)
  2226. Date: Mon, 29 Aug 1994 00:51:29 GMT
  2227. Organization: Wall Data Incorporated
  2228.  
  2229. In article <bb-2708940225150001@user57.lightside.com>, bb@lightside.com
  2230. (Bob Bradley) wrote:
  2231.  
  2232. [ deletia ]
  2233. > I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2234. > the Finder does. I'd like to do something similar to Anarchie but, am not
  2235. > sure how. Anyone have any sample source or suggestions?
  2236. > I'm writing a simple progress bar CDEF that will do progress bars ike
  2237. > normal and support that moving slashed "Not sure how long it will take
  2238. > but, I'm trying" look which I why I want to stay away from PICT's.
  2239.  
  2240. I prefer the term "meat grinder" for the unknown-duration effect :)
  2241.  
  2242. First, I'd suggest looking in the various source code archives on the net.
  2243. There's got to be a CDEF out there that already does this. If not...
  2244.  
  2245. You say you want to stay away from PICTs, but I don't see why. When you
  2246. know how long it's going to take, draw the two gauge parts yourself
  2247. (FillRect or PaintRect each rectangle). When you don't know how long it's
  2248. going to take, just cycle through the four meat grinder PICTs (roll your
  2249. own or just use the Finder's).
  2250.  
  2251. As for the gauge bar color values, here's what I'm using (I think I got
  2252. these by taking screen shots of the Finder's progress dialog and testing
  2253. the color values in Photoshop or something). I imagine there's some RGB
  2254. value that would work in all depths without require a depth test, but
  2255. these look right.
  2256.  
  2257. "Completed" gauge colors:
  2258. 8-bit, dark gray: r=g=b=17476
  2259. 2-bit, dark gray: r=g=b=21845
  2260. 1-bit, black    : r=g=b=0
  2261.  
  2262. "Uncompleted" gauge colors:
  2263. 8-bit, light purple: r=g=54248, b=65535
  2264. 2-bit, light gray  : r=g=b=43690
  2265. 1-bit, white       : r=g=b=65535
  2266.  
  2267. I rolled everything into a TGauge MacApp control class, but since you're
  2268. doing a CDEF, you might want to define special meaning to the control's
  2269. min/max/value to achieve the meat grinder effect. E.g.: if max<min, then
  2270. SetCtlValue cranks the meat grinder. Something like that.
  2271.  
  2272. ..........................................................................
  2273. Trygve Isaacson           trygve@netcom.com         Wall Data Incorporated
  2274. ..........................................................................
  2275.   "Books are burning in the main square
  2276.                         And I saw there the fire eating the text
  2277.      Books are burning in the still air
  2278.                      And you know where they burn books people are next"
  2279.                                                   -- Andy Partridge, XTC
  2280.  
  2281. +++++++++++++++++++++++++++
  2282.  
  2283. >From heathcot@bnr.ca (Graham Heathcote)
  2284. Date: Mon, 29 Aug 1994 00:29:35 GMT
  2285. Organization: BNR Australia
  2286.  
  2287. In article <bb-2708940225150001@user57.lightside.com>, bb@lightside.com
  2288. (Bob Bradley) wrote:
  2289.  
  2290. > I'm trying to implement the Slashed Progress Bar just like Anarchie's when
  2291. > it's trying to connect and similar to the Finder's when it's doing
  2292. > something that it doesn't know how long it will take.
  2293. > I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2294. > the Finder does. I'd like to do something similar to Anarchie but, am not
  2295. > sure how. Anyone have any sample source or suggestions?
  2296. > I'm writing a simple progress bar CDEF that will do progress bars ike
  2297. > normal and support that moving slashed "Not sure how long it will take
  2298. > but, I'm trying" look which I why I want to stay away from PICT's.
  2299.  
  2300. I have just implemented a C++ class to perform the standard progress bar
  2301. and the slashed bar as you call it. I have a few things to finish off and
  2302. then will be placing the sources into c.s.m.
  2303.  
  2304. I thought about implementing the picture method of Finder, but this didn't
  2305. work for my implementation as I wanted the progress bar to be any size as
  2306. defined in the DITL, and the picture needs to be the same size as the user
  2307. item or it will be scalled, YUK. So I went with a pixel pattern (or infact
  2308. 16) and just filled the user item with each successive pattern. This gives
  2309. exactly the same effect as the finder, except since I am using 16 images
  2310. it is much smother than Finder.
  2311.  
  2312. e-mail me if you need any more details, or a preliminary copy of the
  2313. source and example app I have put together.
  2314.  
  2315. Regards,
  2316. Graham Heathcote.
  2317.  
  2318. -- 
  2319. Graham Heathcote
  2320. BNR Australia
  2321. email:   heathcot@bnr.ca
  2322.  
  2323. +++++++++++++++++++++++++++
  2324.  
  2325. >From Matt Slot <fprefect@engin.umich.edu>
  2326. Date: 29 Aug 1994 01:50:48 GMT
  2327. Organization: University of Michigan
  2328.  
  2329. Bob Bradley, bb@lightside.com writes:
  2330.  
  2331. >I'm trying to implement the Slashed Progress Bar just like Anarchie's when
  2332. >it's trying to connect and similar to the Finder's when it's doing
  2333. >something that it doesn't know how long it will take.
  2334. ...
  2335. >I'm writing a simple progress bar CDEF that will do progress bars ike
  2336. >normal and support that moving slashed "Not sure how long it will take
  2337. >but, I'm trying" look which I why I want to stay away from PICT's.
  2338.  
  2339. I downloaded a progress bar CDEF from the archives, one done by
  2340. Eddy J. Gurney from HP, and added the "barber-shop pole" idling effect.
  2341. I sent him a copy and his response was favorable. I will post this to
  2342. alt.sources.mac, with a tester for you to try out.
  2343.  
  2344. The basic idea is that the progress goes from 0 to n (begin -> end), and
  2345. to make it idle you cycle from -4 to -1 (well anything negative MOD 4).
  2346.  
  2347. I can't say its the fastest or best implementation, but it is satisfactory
  2348. for what I have used it in so far.
  2349.  
  2350. Matt
  2351.  
  2352. +++++++++++++++++++++++++++
  2353.  
  2354. >From giles@med.cornell.edu (Aaron Giles)
  2355. Date: 29 Aug 1994 02:14:59 GMT
  2356. Organization: Cornell University Medical College
  2357.  
  2358. In article <bb-2708940225150001@user57.lightside.com>, bb@lightside.com
  2359. (Bob Bradley) wrote:
  2360.  
  2361. > I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2362. > the Finder does. I'd like to do something similar to Anarchie but, am not
  2363. > sure how. Anyone have any sample source or suggestions?
  2364.  
  2365. Well, here is some example code which I used in JPEGView.  Basically, it
  2366. involves setting the PenWidth to a wide pen and drawing some diagonal
  2367. lines.  It is implemented as a dialog user item; each time this user item
  2368. gets called, it increments the position of the bar.  I just do an
  2369. InvalRect() on the user item to get it move one notch.
  2370.  
  2371. // defined elsewhere in the application
  2372. static const RGBColor kBlack = { 0x0000, 0x0000, 0x0000 };
  2373.  
  2374. // draw an indefinite progress bar using the standard Finder colors
  2375. static pascal void UpdateBarIndef(DialogPtr theDialog, short theItem) 
  2376. {
  2377.    static RGBColor gBarBackground = { 0xcccc, 0xcccc, 0xffff };
  2378.    static RGBColor gBarForeground = { 0x4000, 0x4000, 0x4000 };
  2379.    static short gBarOffset = 0;
  2380.    Boolean useBW = !(((CGrafPtr)theDialog)->portVersion & 0xc000) || 
  2381.       (*((CGrafPtr)theDialog)->portPixMap)->pixelSize == 1;
  2382.    short itemType, left;
  2383.    Handle itemHandle;
  2384.    RgnHandle oldClip;
  2385.    GrafPtr oldPort;
  2386.    Rect itemRect;
  2387.    
  2388.    GetPort(oldPort);
  2389.    SetPort(theDialog);
  2390.    GetDItem(theDialog, theItem, &itemType, &itemHandle, &itemRect);
  2391.    if (oldClip = NewRgn()) {
  2392.       GetClip(oldClip);
  2393.       PenSize(1, 1);
  2394.       RGBForeColor(&kBlack);
  2395.       FrameRect(&itemRect);
  2396.       InsetRect(&itemRect, 1, 1);
  2397.       ClipRect(&itemRect);
  2398.       left = itemRect.left - (3 * Height(&itemRect)) + 
  2399.              (gBarOffset * Height(&itemRect) / 2);
  2400.       PenSize(Height(&itemRect), 1);
  2401.       while (left < itemRect.right) {
  2402.          RGBForeColor(&gBarForeground);
  2403.          MoveTo(left, itemRect.top);
  2404.          LineTo(left += Height(&itemRect), itemRect.bottom);
  2405.          if (useBW) RGBForeColor(&kWhite);
  2406.          else RGBForeColor(&gBarBackground);
  2407.          MoveTo(left, itemRect.top);
  2408.          LineTo(left += Height(&itemRect), itemRect.bottom);
  2409.       }
  2410.       PenSize(1, 1);
  2411.       SetClip(oldClip);
  2412.       DisposeRgn(oldClip);
  2413.       gBarOffset = (gBarOffset + 1) & 3;
  2414.    }
  2415.    RGBForeColor(&kBlack);
  2416.    SetPort(oldPort);
  2417. }
  2418. -- 
  2419. Aaron Giles (giles@med.cornell.edu)
  2420. Power Macintosh Developer, Cornell University Medical College
  2421. JPEGView home page: http://www.med.cornell.edu/jpegview.html
  2422. JPEGView FTP site:   ftp://ftp.med.cornell.edu/pub/aarong/jpegview/
  2423.  
  2424. +++++++++++++++++++++++++++
  2425.  
  2426. >From alexr@apple.com (Alex Rosenberg)
  2427. Date: Mon, 29 Aug 1994 07:59:37 GMT
  2428. Organization: Hackers Anonymous
  2429.  
  2430. In article <heathcot-2908941028320001@47.181.192.70>, heathcot@bnr.ca
  2431. (Graham Heathcote) wrote:
  2432.  
  2433. > In article <bb-2708940225150001@user57.lightside.com>, bb@lightside.com
  2434. > (Bob Bradley) wrote:
  2435. > > I'm trying to implement the Slashed Progress Bar just like Anarchie's when
  2436. > > it's trying to connect and similar to the Finder's when it's doing
  2437. > > something that it doesn't know how long it will take.
  2438. > > 
  2439. > > I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2440. > > the Finder does. I'd like to do something similar to Anarchie but, am not
  2441. > > sure how. Anyone have any sample source or suggestions?
  2442. > > 
  2443. > > I'm writing a simple progress bar CDEF that will do progress bars ike
  2444. > > normal and support that moving slashed "Not sure how long it will take
  2445. > > but, I'm trying" look which I why I want to stay away from PICT's.
  2446. > I have just implemented a C++ class to perform the standard progress bar
  2447. > and the slashed bar as you call it. I have a few things to finish off and
  2448. > then will be placing the sources into c.s.m.
  2449. > I thought about implementing the picture method of Finder, but this didn't
  2450. > work for my implementation as I wanted the progress bar to be any size as
  2451. > defined in the DITL, and the picture needs to be the same size as the user
  2452. > item or it will be scalled, YUK. So I went with a pixel pattern (or infact
  2453. > 16) and just filled the user item with each successive pattern. This gives
  2454. > exactly the same effect as the finder, except since I am using 16 images
  2455. > it is much smother than Finder.
  2456.  
  2457. Instead of using multiple patterns, you can get the same effect by moving
  2458. the origin with a SetOrigin call. (As I do in XMODEM Tool 1.1.)
  2459.  
  2460. - -------------------------------------------------------------------------
  2461. -  Alexander M. Rosenberg  - INTERNET: alexr@apple.com      - Yoyodyne    -
  2462. -  330 Waverley St., Apt B - UUCP:ucbvax!apple!alexr        - Propulsion  -
  2463. -  Palo Alto, CA 94301     -                                - Systems     -
  2464. -  (415) 329-8463          - Nobody is my employer so       - :-)         -
  2465. -  (408) 974-3110          - nobody cares what I say.       -             -
  2466.  
  2467. +++++++++++++++++++++++++++
  2468.  
  2469. >From msguzzo@srqa01.jsc.nasa.gov (Michael Guzzo)
  2470. Date: Mon, 29 Aug 1994 15:20:45
  2471. Organization: Calspan/Space Shuttle Safety & Mission Assurance
  2472.  
  2473. In article <bb-2708940225150001@user57.lightside.com> bb@lightside.com (Bob Bradley) writes:
  2474. >From: bb@lightside.com (Bob Bradley)
  2475. >Subject: Slashed Progress Bar
  2476. >Date: Sat, 27 Aug 1994 02:25:15 -0800
  2477.  
  2478. >I'm trying to implement the Slashed Progress Bar just like Anarchie's when
  2479. >it's trying to connect and similar to the Finder's when it's doing
  2480. >something that it doesn't know how long it will take.
  2481.  
  2482. >I've looked at Anarchie and it doesn't seem to use a PICT resource like
  2483. >the Finder does. I'd like to do something similar to Anarchie but, am not
  2484. >sure how. Anyone have any sample source or suggestions?
  2485.  
  2486. >I'm writing a simple progress bar CDEF that will do progress bars ike
  2487. >normal and support that moving slashed "Not sure how long it will take
  2488. >but, I'm trying" look which I why I want to stay away from PICT's.
  2489.  
  2490. How about using two ppats? Set the pen height and width to the height of 
  2491. your progress bar using the ppat, draw a filled rect, and then switch to the 
  2492. other ppat.. continue until you're done. Draw the ppat to look like the 
  2493. barberpole is moving.
  2494.  
  2495. Just off the top of my head, I don't have any sample code...
  2496.  
  2497. ________________________________________________________________________
  2498. Michael S. Guzzo
  2499. msguzzo@srqa01.jsc.nasa.gov
  2500. You're gonna have to face it, you're addicted to Doom!
  2501.  
  2502. +++++++++++++++++++++++++++
  2503.  
  2504. >From Chris Ferris <chris@tycho.demon.co.uk>
  2505. Date: Sun, 4 Sep 1994 15:16:44 GMT
  2506. Organization: Tycho Consultants
  2507.  
  2508.  
  2509. In article <msguzzo.72.000F590A@srqa01.jsc.nasa.gov>, Michael Guzzo 
  2510. writes:
  2511.  
  2512. >
  2513. > In article <bb-2708940225150001@user57.lightside.com> 
  2514. bb@lightside.com (Bob Bradley) writes:
  2515. > >From: bb@lightside.com (Bob Bradley)
  2516. > >Subject: Slashed Progress Bar
  2517. > >Date: Sat, 27 Aug 1994 02:25:15 -0800
  2518. > >I'm trying to implement the Slashed Progress Bar...
  2519.  
  2520. [ Stuff cut ]
  2521.  
  2522. > How about using two ppats? Set the pen height and width to the 
  2523. height of 
  2524. > your progress bar using the ppat, draw a filled rect, and then 
  2525. switch to the 
  2526. > other ppat.. continue until you're done. Draw the ppat to look like 
  2527. the 
  2528. > barberpole is moving.
  2529.  
  2530.  
  2531. There is a simpler solution using only one ppat. Define a single ppat 
  2532. for the 'barbers pole' which is black and white separated diagonaly 
  2533.  
  2534. 11111111 = 0xFF
  2535. 01111111 = 0x7F
  2536. 00111111 = 0x3F
  2537. 00011111 = 0x1F
  2538. 00001111 = 0x0F
  2539. 00000111 = 0x07
  2540. 00000011 = 0x03
  2541. 00000001 = 0x01
  2542.  
  2543. Inside your progress bar function use SetOrigin to move the 
  2544. co-ordinate system used by QD patterns by one pixel horizontally for 
  2545. each update to the bar, resetting to 0 when you reach 8.
  2546.  
  2547. The pattern will appear to move along the progress bar, just remember 
  2548. to compensate for the change in co-ordinates before calling FillRect.
  2549.  
  2550.  
  2551.    ___       |                 chris@tycho.demon.co.uk
  2552.   /  ___     |             Chris Ferris, Tycho Consultants
  2553.  /__/_       |
  2554.    /         |  'The best way to predict the future is to invent it!'
  2555.   /          |                          Apple Computer Inc
  2556.  
  2557.  
  2558. ---------------------------
  2559.  
  2560. End of C.S.M.P. Digest
  2561. **********************
  2562.  
  2563.  
  2564. ˇ